express use ejs template engine to render html file

Tips little scene.

In the course of using the express, according to the official website tutorial for express generator it is easy to initialize express project template.

After initializing the project should then how to use as a template engine ejs it? as follows

// generates a default configuration commented 
// Setup View Engine 
// app.set ( 'views', path.join (__ dirname, 'views')); 
// app.set ( 'Engine View', 'Jade'); 

app.set ( 'views', path.join ( __ dirname,' views')); // set the static directory 
//app.engine('.html ', the require (' EJS ') .__ Express); 
 app.set ( 'view engine', 'ejs '); // set the template engine

How to use ejs render html file it?

// View Engine Setup
 // app.set ( 'views', path.join (__ dirname, 'views'));
 // app.set ( 'Engine View', 'Jade'); 


. App SET ( ' views ' , path.join (__ dirname, ' views ' )); // set a static file directory 
app.engine ( ' .html ' , The require ( ' ejs ' ) .__ Express); // set ejs render HTML 
 . App the sET ( ' View Engine ' , ' HTML ' );// set html template engine to note here is the html

  After setting in accordance with the above, if you do not set the rendering html file, the default service will be rendered .ejs under static file directory,

If set to render html file, it will default to render html file with the extension.

Guess you like

Origin www.cnblogs.com/zhensg123/p/11058028.html