npm isntall ejs
var ejs = require("ejs"); var tpl = "<% myList.forEach(function(item){ %>hello <%=item%> <br /> <% }) %> "; var data = {"myList":["hehe","xixi"]}; console.log(ejs.render(tpl,data));
参考文档:https://www.npmjs.com/package/ejs