Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var db = mongoose.connect('mongodb://localhost:27017/DB');
- // In middleware
- app.use(function (req, res, next) {
- // action after response
- var afterResponse = function() {
- logger.info({req: req}, "End request");
- // any other clean ups
- mongoose.connection.close(function () {
- console.log('Mongoose connection disconnected');
- });
- }
- // hooks to execute after response
- res.on('finish', afterResponse);
- res.on('close', afterResponse);
- // do more stuff
- next();
- }
Add Comment
Please, Sign In to add comment