Nodejs uses Express to build Web projects, using HTML files instead of jade templates __c languages

Source: Internet
Author: User

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:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.