Guest User

Untitled

a guest
Dec 10th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. var db = mongoose.connect('mongodb://localhost:27017/DB');
  2.  
  3. // In middleware
  4. app.use(function (req, res, next) {
  5.  
  6. // action after response
  7. var afterResponse = function() {
  8. logger.info({req: req}, "End request");
  9.  
  10. // any other clean ups
  11. mongoose.connection.close(function () {
  12. console.log('Mongoose connection disconnected');
  13. });
  14. }
  15.  
  16. // hooks to execute after response
  17. res.on('finish', afterResponse);
  18. res.on('close', afterResponse);
  19.  
  20. // do more stuff
  21.  
  22. next();
  23. }
Add Comment
Please, Sign In to add comment