What's the difference between “app.render” and “res.render” in express.js?

前端 未结 3 613
我寻月下人不归
我寻月下人不归 2020-12-07 08:52

Docs for app.render:

Render a view with a callback responding with the rendered string. This is the app-level variant of res.render(), an

3条回答
  •  一向
    一向 (楼主)
    2020-12-07 09:42

    along with these two variants, there is also jade.renderFile which generates html that need not be passed to the client.

    usage-

    var jade = require('jade');
    
    exports.getJson = getJson;
    
    function getJson(req, res) {
        var html = jade.renderFile('views/test.jade', {some:'json'});
        res.send({message: 'i sent json'});
    }
    

    getJson() is available as a route in app.js.

提交回复
热议问题