Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. var mongoose = require("mongoose");
  2.  
  3. var dbURI = 'mongodb://localhost/Loc8r';
  4. mongoose.connect(dbURI);
  5.  
  6. mongoose.connection.on('connected', function () {
  7. console.log('Mongoose connected to ' + dbURI);
  8. });
  9. mongoose.connection.on('error',function (err) {
  10. console.log('Mongoose connection error: ' + err);
  11. });
  12. mongoose.connection.on('disconnected', function () {
  13. console.log('Mongoose disconnected');
  14. });
  15.  
  16. var gracefulShutdown = function (msg, callback) {
  17. mongoose.connection.close(function () {
  18. console.log('Mongoose disconnected through ' + msg);
  19. callback();
  20. });
  21. };
  22.  
  23. process.once('SIGUSR2', function () {
  24. gracefulShutdown('nodemon restart', function () {
  25. process.kill(process.pid, 'SIGUSR2');
  26. });
  27. });
  28. process.on('SIGINT', function () {
  29. gracefulShutdown('app termination', function () {
  30. process.exit(0);
  31. });
  32. });
  33. process.on('SIGTERM', function() {
  34. gracefulShutdown('Heroku app shutdown', function () {
  35. process.exit(0);
  36. });
  37. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement