Node.js - EJS example

后端 未结 3 579
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 15:14

I am trying to use Embedded Javascript renderer for node. I installed it using npm, as given here: https://github.com/visionmedia/ejs

And I have the following code, but

3条回答
  •  不知归路
    2021-02-05 15:35

    Set your view engine to use ejs.

    app.set("view engine", "ejs");
    

    Now set up the root route so that it will load something when you access your server from a browser, see below.

    var app = express();
    
    // ROOT ROUTE
    app.get("/", function(req, res) {
      res.render("landingpage"); // use to render an ejs template page
      res.send("hello world"); // to render an empty page with the hello world message
    });
    

提交回复
热议问题