I'm using express 3 in my node application and I've broken my routes into separate files...
app.use('/', routes);
app.use('/users', users);
The problem is that I need a database connection in many of these routes. Should I be connecting to the database in each of the route files or can I connect in my main app file and somehow pass the connection to the includes?
I used express-generator to create a skeleton app. In app.js the routes are included like this...
app.use('/', routes);
app.use('/users', users);
And in each other these files there are routes as follows...
var express = require('express');
var router = express.Router();
router.get('/', function(req, res) {
res.render('index');
});