Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
192
rated 0 times [  196] [ 4]  / answers: 1 / hits: 20910  / 10 Years ago, sun, august 10, 2014, 12:00:00

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


More From » node.js

 Answers
6

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.




Edit: Since this answer got marked as correct and it's the most upvoted, It's my duty to point you to the one further below by Vlad Pana https://stackoverflow.com/a/44007538/1030087


Quire a few keynames you set on the app instance do have a special meaning.


[#69836] Friday, August 8, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tristab

Total Points: 735
Total Questions: 106
Total Answers: 96

Location: Grenada
Member since Sun, Dec 20, 2020
3 Years ago
tristab questions
Sat, Sep 25, 21, 00:00, 3 Years ago
Sun, Jan 31, 21, 00:00, 3 Years ago
Wed, Dec 2, 20, 00:00, 4 Years ago
Fri, Oct 23, 20, 00:00, 4 Years ago
;