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.
- 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.
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:
- Open browser and type this URL:
- 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.
- How to Setup Handlebars View Engine in Node.js ?
- Nodejs | Automatic restart NodeJs server with nodemon
- Introduction to Model View View Model (MVVM)
- Search Engine Optimization (SEO) | Basics
- Mobile Search Engine Optimization (SEO)
- Elasticsearch Search Engine | An introduction
- Use EJS as Template Engine in Node.js
- How to detect search engine bots with PHP ?
- Difference between Search Engine and Web Browser
- How to use underscore.js as a template engine ?
- Express.js app.engine() Function
- AWS EC2 Instance Setup with Apache Server
- Environment setup for JSP
- Setup API for GeeksforGeeks user data using WebScraping and Flask
- Angular CLI | Angular Project Setup
- p5.js | setup() Function
- ES6 | Environment Setup
- Setup Sending Email in Django Project
- How to Setup Sublime Text 3 for Python in Windows?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.