From e1d7a8bc679a0a7ee374a2f25eb7cac017680344 Mon Sep 17 00:00:00 2001 From: rohit <153482419+mr-saadhak@users.noreply.github.com> Date: Tue, 3 Mar 2026 20:37:28 +0530 Subject: [PATCH] fix: typos fix --- server.js | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/server.js b/server.js index 3f5a2ae..5bdc267 100644 --- a/server.js +++ b/server.js @@ -2,7 +2,6 @@ import 'dotenv/config'; import http from 'http'; import app from './src/app.js'; import connectDB from './src/config/db.js'; -import { start } from 'repl'; const PORT = process.env.PORT || 5000; const NODE_ENV = process.env.NODE_ENV || 'development'; @@ -35,35 +34,39 @@ const startServer = async() => { startServer(); -process.on("unhandledRejection", (err) => { - console.error("Unhandled Rejection: ", err); - shutdownGracefully(); -}); - -process.on("uncaughtException", (err) => { - console.error("Uncaught Exception: ", err); - shutdownGracefully(); -}); - -const shutdownGracefully = () => { +const shutdownGracefully = (exitCode = 0) => { if (server) { server.close(() => { - console.log("Server closed grecefully"); - process.exit(1); + console.log("Server closed gracefully"); + process.exit(exitCode); }); + + setTimeout(() => { + console.error("Forced shutdown after timeout"); + process.exit(exitCode); + }, 10000).unref(); } else { - process.exit(1); + process.exit(exitCode); } }; +process.on("unhandledRejection", (err) => { + console.error("Unhandled Rejection: ", err); + shutdownGracefully(1); +}); + +process.on("uncaughtException", (err) => { + console.error("Uncaught Exception: ", err); + shutdownGracefully(1); +}); + process.on("SIGTERM", () => { console.log("SIGTERM received. Shutting down..."); shutdownGracefully(); }); process.on("SIGINT", () => { - console.log("SIGINT reveiced. Shutting down..."); + console.log("SIGINT received. Shutting down..."); shutdownGracefully(); -}); - +}); \ No newline at end of file