आपका app.use
आपके app.get
. से पहले लिखा होना चाहिए . app.get
एक्सप्रेस द्वारा पहले कहा जाता है।
var mongo = require('mongodb');
var monk = require('monk');
var db = monk('localhost:27017/notepad');
var app = express();
// mongoDB
// Do all your "pre-route" use() functions first
app.use(function (req, res, next) {
req.locals.db = db; // this is setting up db property to request
next();
});
app.get('/users', routes.userlist);
आपके मार्गों में...
var db = req.locals.db; // Instead of req.db
या इससे भी बेहतर...
var mongo = require('mongodb');
var monk = require('monk');
var db = monk('localhost:27017/notepad');
var app = express();
app.locals.db = db;
app.get('/users', routes.userlist); // Access it using req.locals.db