How do i set a variable in app.js and have it be available in all the routes, atleast in the index.js file located in routes. using the express framework and node.js
How do i set a variable in app.js and have it be available in
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To make a global variable, just declare it without the
varkeyword. (Generally speaking this isn’t best practice, but in some cases it can be useful – just be careful as it will make the variable available everywhere.)Here’s an example from visionmedia/screenshot-app
file app.js:
file routes/main.js