I just started using a new version of Express (2.5.5) that by default creates a ./routes
directory along with ./views
and ./public
Inside of routes there is a index.js
file which contains:
/*
* GET home page.
*/
exports.index = function(req, res){
res.render('index', { title: 'Express' })
};
by default (after running express
from the commandline) and this is the routes section in the main app.js
:
// Routes
app.get('/', routes.index);
I've set up a variable for a redis client in the main app.js
:
var redis = require('redis'),
db = redis.createClient();
and I was wondering how I could access the methods of db
(and whatever other modules I require
in app.js
) in the files contained in ./routes
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…