![]() |
VOOZH | about |
A view engine is a tool used in web development to create dynamic HTML content based on data from the server. It acts as a template processor that allows you to integrate data with predefined HTML templates easily.
In this article, we will learn about the Importance of view engines on server side rendering with example.
View engines are important for server-side rendering (SSR) because they allow you to create dynamic web pages by putting variables, loops, and other logic into HTML templates. It makes easier to keep your code organized and readable.
It is a combination of HTML tags, server controls and a programming language. It works inside the application to render views to the browser or to the user. The main job of the view engine is to compile components and templates into a set of instructions that can be understood and rendered by the browser.
Step 1: Create a NodeJS application using the following command:
npm init -yStep 2: Install required Dependencies:
npm i ejs expressThe updated dependencies in package.json file will look like:
"dependencies": {
"ejs": "^3.1.9",
"express": "^4.18.2"
}
Example: The below example is demonstrating the EJS View Engine for Express.
Step 4: To run the application use the following command
node index.js Output: Now go to http://localhost:3000 in your browser: