How to Setup View Engine in Node.js ? Last Updated : 27 Apr, 2020 Comments Improve Suggest changes Like Article Like Report View engines are useful for rendering web pages. There are many view engines available in the market like Mustache, Handlebars, EJS, etc but the most popular among them is EJS which simply stands for Embedded JavaScript. It is a simple templating language/engine that lets its user generate HTML with plain javascript. Installation of ejs module: You can visit the link Install ejs module. You can install this package by using the following command. npm install ejs After installing multer you can check your ejs version in command prompt using the command. npm version ejs After that, you can just create a folder and add a file for example app.js, To run this file you need to run the following command. node app.js To setup view engine, you need the write this middleware in your index.js as follow: app.set('views', path.join(__dirname, 'views')) app.set('view engine', 'ejs') where path is the global object and __dirname holds current directory address. Views is the folder where our all web pages will be kept. Now create a EJS file like Demo.ejs and put this file in views folder. Filename: Demo.ejs html <!DOCTYPE html> <html> <head> <title>View Engine Demo</title> </head> <body> <!- For printing variable these tags are used: <%= %> --> <h1> <%= title %> </h1> <!- For business logic these tags are used: <% %> --> <% if(true){ %> <h4>Greetings from geeksforgeeks</h4> <% } %> </body> </html> Filename: app.js javascript const express = require('express') const path = require('path') const app = express() // View Engine Setup app.set('views', path.join(__dirname, 'views')) app.set('view engine', 'ejs') app.get('/', function(req, res){ // Rendering our web page i.e. Demo.ejs // and passing title variable through it res.render('Demo', { title: 'View Engine Demo' }) }) app.listen(8080, function(error){ if(error) throw error console.log("Server created Successfully") }) Steps to run the program: The project structure will look like this: Make sure you have 'view engine' like I have used "ejs" and also install express using the following commands: npm install ejs npm install express Run app.js file using below command: node app.js Open browser and type this URL: http://localhost:8080/ Then you will see the Demo.ejs page as shown below: So this is how you can setup a view engine in node js. There are many other engines exist like Handlebars, Mustache, etc. Comment More infoAdvertise with us Next Article How to Setup View Engine in Node.js ? G gouravhammad Follow Improve Article Tags : JavaScript Web Technologies Node.js Write From Home Node.js-Misc +1 More Similar Reads How to Setup Handlebars View Engine in Node.js ? Handlebars is a template engine that is widely used and easy to use. The pages contain .hbs extension and there are many other template engines in the market like EJS, Mustache, etc. Installation of hbs module: You can visit the link Install hbs module. You can install this package by using this com 2 min read Use EJS as Template Engine in Node.js EJS (Embedded JavaScript) is a popular templating engine for Node.js that allows you to generate HTML markup with plain JavaScript. It is particularly useful for creating dynamic web pages, as it enables you to embed JavaScript logic directly within your HTML.EJSEJS or Embedded Javascript Templating 4 min read How to use Template Engines in Express JS ? Express.js is a popular web framework for Node.js that simplifies the process of building web applications. One of the key features of Express is its ability to integrate with template engines, allowing developers to dynamically generate HTML pages with data from their server. In this article, we'll 3 min read Explain V8 engine in Node.js The V8 engine is one of the core components of Node.js, and understanding its role and how it works can significantly improve your understanding of how Node.js executes JavaScript code. In this article, we will discuss the V8 engineâs importance and its working in the context of Node.js.What is a V8 7 min read How to Configure multiple View Engines in Express.js ? View engines present in web application framework are basically the template engines that allow us to embed dynamic content into the web pages, render them on the server, and send them to the client. With the help of these, we can serve dynamic data, and utilise the template inheritance properties t 3 min read Like