What is the difference between setting a property on app.locals and calling app.set()?

前端 未结 4 677
迷失自我
迷失自我 2021-02-05 07:09

I\'m in the process of learning Express - and thinking of the best place to save config style data. Options available are either in app.locals or app.set (settings)... so:

4条回答
  •  天命终不由人
    2021-02-05 07:29

    The express api reference says :

    By default Express exposes only a single app-level local variable, settings.

    and either way is ok:

    app.locals.title = 'My App';
    
    app.set('title', 'My App');
    // use settings.title in a view
    

提交回复
热议问题