简体   繁体   中英

Quick question about nodeJs and rendering templates

So I'm learning the express framework for nodejs and am curious if I need a templating engine like ejs or pug to use the res.render('index.ejs') function to serve html.

It seems like when I tried to serve up a basic html page without the template, it failed when I navigated to the page, res.render(index.html) .

So I guess my question is, if I use res.render() in express, do i have no choice but to use a templating engine?

You need to use res.send file found here res.render is usually used to render a template via a template engine. So it is up to how you design the project - whether you send all your html code from server via a template engine - or use a client side app like angular .

i had the same problem and they recommended me to try this

 app.engine('html', require('ejs').renderFile);

it did not work for me, but maybe it will work for you.

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