In some projects, such as you take over someone else's project and you don't want to use the Ejs, or you don't want to use the egg-sore jade. You do not want to rewrite the previous page, then you may now need to introduce a new Ejs or Jade module, you just need to do the following two steps may be completed using two templates work
1.consolidate.js
CD to project directory:
NPM Install consolidate--save
Open the project's App.js (maybe your name is other)
Take the shape of the app.js like the code snippet below
App.set (' View engine ', ' Jade ');
Switch
var engines = require (' consolidate '); App.engine (' Jade ', Engines.jade); App.engine (' html ', Engines.ejs);//or use these/ /app.engine (' Jade ', require (' Jade '). __express);//App.engine (' HTML ', require (' Ejs '). RenderFile); App.set (' View Engine ', ' Jade ');
You can restart the project.
2. A little problem
In one of my project A, the code I actually used was
var engines = require (' consolidate '); App.engine (' Jade ', Engines.jade); App.engine (' html ', Engines.ejs);//App.engine ( ' Jade ', require (' Jade '). __express);//App.engine (' HTML ', require (' Ejs ') renderfile); App.set (' View engine ', ' Jade ') ;//More than one line App.set (' View engine ', ' html ');
This notation can be used in project a, but found in another project B cannot parse the jade template
In Project B, you can only use the
var engines = require (' consolidate '); App.engine (' Jade ', Engines.jade); App.engine (' html ', Engines.ejs); App.set (' View Engine ', ' jade ');//or//app.engine (' Jade ', require (' Jade ') __express);//app.engine (' HTML ', require (' Ejs '). RenderFile);//app.set (' View engine ', ' Jade ');
Ask the Friends of the park to help answer the question why?
EJS Jade Consolidate version consistent Express version 4.12.x
Nodejs Express Framework works with Ejs templates and Jade templates in one project