Escape HTML in node.js EJS view
Step 1: Create a folder or go to the existing folder
mkdir escape-html
cd escape-html
Step 2: Create a server using the following command
npm init -y
Step 3: Install the required dependencies.
npm i express ejs
Folder Structure:
Dependencies:
"dependencies": {
"ejs": "^3.1.9",
"express": "^4.19.2"
}
How to Escape HTML in NodeJS EJS View ?
When working with web applications in Node.js using the EJS templating engine, it’s important to ensure that user-generated content containing HTML is rendered safely. Otherwise, it can lead to security vulnerabilities such as cross-site scripting (XSS) attacks.