Node.js : How to embed Node.js into HTML?

前端 未结 3 1228
一整个雨季
一整个雨季 2020-12-31 04:33

In a php file I can do:

Is there a way to do this in node, if yes what\'

3条回答
  •  礼貌的吻别
    2020-12-31 05:31

    Use a template engine. From terminal

    npm install ejs
    

    In code:

    var ejs = require('ejs');
    
    var options = {
      locals: {
        foo: function() { return "bar"; }
      }
    };
    
    var template = "

    <%= foo() %>

    "; console.log(ejs.render(template, options));

提交回复
热议问题