Skip to content
Snippets Groups Projects
Commit 7b1794f2 authored by Lucendio's avatar Lucendio
Browse files

Get rid of redundant DB shutdown and move it to main()

parent 4f707671
No related branches found
No related tags found
No related merge requests found
......@@ -36,10 +36,4 @@ mongooseInstance_
});
process.on( 'exit', async ()=>{
const dbClient = await mongooseInstance_;
dbClient.disconnect();
});
module.exports = mongooseInstance_;
......@@ -44,21 +44,24 @@ app.use(errorRoutes);
(async function main(){
process.on( 'exit', async ()=>{
const dbClient = await dbClientInstance_;
await dbClient.disconnect();
});
try{
const server = http.createServer( app );
await new Promise( (__ful, rej__ )=>{
server.listen(port, function(){
console.log( `ToDo server is up on port ${ port }`);
server.listen( port, ()=>{
console.log( `ToDo server is up & bound to port ${ port }` );
__ful();
}).on( 'error', rej__);
}).on( 'error', rej__ );
});
process.on( 'SIGINT', async ()=>{
process.on( 'SIGINT', ()=>{
server.close( ()=>{
console.log( 'Shutting ToDo server' );
console.log( 'Shutting down ToDo server' );
});
const dbClient = await dbClientInstance_;
await dbClient.disconnect();
process.exit( 0 );
});
}catch( err ){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment