Node/Express.js - Overriding where to look for the 'Views' folder for each request

后端 未结 3 1762
南笙
南笙 2021-02-03 23:18

In my Node/Express.js project I can set the views folder globally like so:

app.configure(function() {
    app.set(\'views\', __dirname + \'/views\');
    .... sn         


        
3条回答
  •  无人共我
    2021-02-04 00:18

    The 'views' setting is the root directory, so you should be able to specify a sub-folder in the hierarchy:

    app.get('/', function(req, res) {
        res.render('areaName/viewName');
    });
    

    It means your 'areas' need to be sub-folders, but it allows you to accomplish the separation you are looking for.

提交回复
热议问题