What app.set function does (express.js)?

前端 未结 3 1585
攒了一身酷
攒了一身酷 2021-02-13 14:09

I am new to node.js and was going through an example could not understand app.set(\'title\', \'My Site\'); does please help?

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-13 14:41

    You can use the express instance to store and retrieve variables. In this case, you can set the title to be "My Site" and retrieve it later with something like

    var title = app.get('title');
    

    without the need to declare and keep a global variable messing around.

    The name of the parameter means nothing. You could do

    app.set('jabberwocky', 'correct battery horse staples');
    

    as well. If you're using express with jade, for example, you might need to retrieve the value of 'jabberwocky' in a template, further along the line.

提交回复
热议问题