Bloggers use Webstrom development tools to create the Node.js Express app project, which is actually a Web project.
After the success of the creation, you can look at the project structure:
3 are generated in the views directory. Jade template file, the format of the template is the Express default template engine, as for the pros and cons, we check, anyway, bloggers are not accustomed to such template writing, or HTML is used to write, then how to replace the template engine, you can use HTML templates.
The solution is to use the other template engine for Express, Ejs,node Ejs is an express templates parsing engine for parsing HTML templates to generate the corresponding HTML parser. syntax is similar to PHP, syntax is more intuitive.
1, open the App.js file, find the template engine settings where
Modified into:
This requires installing the Ejs module and installing it into the project directory using the NPM command.
2, the Views directory template file use. html file replacement
3, run the project, access to the project address.
Finally, we introduce the differences between the Ejs in the template presentation data:
1. <% code%> is used to execute JavaScript codes in them;
2, <%= code%> will be the code for HTML escape;
3, <%-code%> will not be escaped;
Here is an example:
When you access the project address, you receive a request to return data, title, and an array of users.
Front End display:
Front-End template processing data methods: