Home >Web Front-end >JS Tutorial >When node.js uses the ejs template engine, the suffix is ​​changed to .html_node.js

When node.js uses the ejs template engine, the suffix is ​​changed to .html_node.js

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 16:02:461259browse

This is a little trick. I always feel uncomfortable looking at the .ejs suffix. Use the following method to change the suffix of the template file to the .html we are used to.

1. Define ejs at the head of app.js:

Copy code The code is as follows:

var ejs = require('ejs');

2. Register html template engine:

Copy code The code is as follows:

app.engine('html',ejs.__express);

3. Change the template engine to html:

Copy code The code is as follows:

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

4. Modify the suffix of the template file to .html.

Okay, the task is completed, you can run and watch the effect!

The above is the entire content of this article, I hope you all like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn