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 fra
My preferred way is to use circular dependencies*, which node supports
var app = module.exports = express();
as your first order of businessvar app = require('./app')
to access itvar express = require('express');
var app = module.exports = express(); //now app.js can be required to bring app into any file
//some app/middleware, config, setup, etc, including app.use(app.router)
require('./routes'); //module.exports must be defined before this line
var app = require('./app');
app.get('/', function(req, res, next) {
res.render('index');
});
//require in some other route files...each of which requires app independently
require('./user');
require('./blog');