How do I use HTML as the view engine in Express?
To make the render engine accept html instead of jade you can follow the following steps;
Install consolidate and swig to your directory.
npm install consolidate npm install swig
add following lines to your app.js file
var cons = require('consolidate');// view engine setupapp.engine('html', cons.swig)app.set('views', path.join(__dirname, 'views'));app.set('view engine', 'html');
add your view templates as .html inside “views” folder. Restart you node server and start the app in the browser.
Though this will render html without any issue, I would recommend you to use JADE by learning it. Jade is an amazing template engine and learning this will help you achieve better design & scalability.
In your apps.js just add
// view engine setupapp.set('views', path.join(__dirname, 'views'));app.engine('html', require('ejs').renderFile);app.set('view engine', 'html');
Now you can use ejs view engine while keeping your view files as .html
source: http://www.makebetterthings.com/node-js/how-to-use-html-with-express-node-js/
You need to install this two packages:
npm install ejs --savenpm install path --save
And then import needed packages:
var path = require('path');
This way you can save your views as .html instead of .ejs.
Pretty helpful while working with IDEs that support html but dont recognize ejs.