Graceful Shutdown for mongodb

This commit is contained in:
tenthirtyone 2017-08-24 15:01:43 -04:00
parent 333eec3dd8
commit 12cb8a0c29

View File

@ -9,6 +9,15 @@ mongoose.connection.on('error', (err) => {
${err}`);
});
process.on('SIGINT', gracefulExit).on('SIGTERM', gracefulExit);
function gracefulExit() {
mongoose.connection.close(() => {
console.log('Mongoose connection with DB disconnected through app termination');
process.exit(0);
});
}
module.exports = {
connect: mongoose.connect,
connection: mongoose.connection,