简体   繁体   中英

why to use jade or any other template in node.js

Why we use jade or any other template in node.js(express.js). We can use send method to send file html file and what is the meaning of rendering the HTML.

You can choose to directly send back a static HTML file in the filesystem if you wish, but that wouldn't be very useful if you wanted to show dynamic content.

Using templates like jade, you can easily inject data from your application logic into the returned page.

Well, I would say there are actually different philosophies of design at work.

As others have said, you can use Jade or other templating engines to render server-side variables in your HTML that gets written to the client.

Others would argue that this is not the best design, and that it's better to render static HTML that uses clientside JavaScript as an API client, and have your Node process only expose a RESTful API.

Either approach works and has pro's and con's, but I think the latter is somewhat more 'modern' and flexible if you have to start thinking about other possible clients for your app (eg mobile native apps).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM