Graceful Shutdown for mongodb
This commit is contained in:
parent
333eec3dd8
commit
12cb8a0c29
@ -9,6 +9,15 @@ mongoose.connection.on('error', (err) => {
|
|||||||
${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 = {
|
module.exports = {
|
||||||
connect: mongoose.connect,
|
connect: mongoose.connect,
|
||||||
connection: mongoose.connection,
|
connection: mongoose.connection,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user