In file app.js i have:
, mongoose = require('mongoose')
, db = mongoose.connect('mongodb://localhost/expressdb');
app.get('/', routes.index);
and i have file routes/index.js, If I want to transfer db variable to routes.index What should I do?
I’ve setup an example on how you can achieve that, by passing the db as a parameter to the route module, and that module returns a function (in which db is visible):
routes.index
app.js