Current location - Education and Training Encyclopedia - Resume - Help nodejs+ express how to realize static dynamic pages.
Help nodejs+ express how to realize static dynamic pages.
In fact, it just needs a compilation process.

Template+data-> static html file

I don't know what template engine you are using, such as ejs, jade, nunjucks, swig and so on. In fact, what you spit out in the end is compiled, but what you need is actually to save these as files.

Take nunjucks as an example:

var tpl = ' index.tpl

var data = get data(); //Somewhere

var content = nunjucks.render(tpl,data);

fs.writeFileSync('index.html ',content);

The index.html generated above is the static file you want.