How To Change Template Engine In Express.js

If you don’t have a view engine set in your express/node application, you need to specify file extension with each of your view files. To fix this issue you need to set a default view engine for rendering views.

You can set a template engine using following code.

app.set('view engine', 'jade')

The above code will set Jade as the default template engine. You can change jade with your own templating engine. For example, if you wish to set ejs as your default template engine, use following code.

app.set('view engine', 'ejs')

Read Also: How to use EJS in Express

How To Use EJS with Express

In this tutorial, we are going to configure EJS template engine in Express/Node application.

To install EJS inside your ExpressJS project follow the steps given below,

01. Navigate to your project folder and run the following command,

npm install ejs --save  

02. Now, you need to set ejs as your default view engine. You can do this by using following code.

app.set('view engine', 'ejs');

Read Also: Angularjs filter To Output Plain Text Instead Of HTML