Skip to content

Commit e1d7a8b

Browse files
committed
fix: typos fix
1 parent eb3570a commit e1d7a8b

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

server.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'dotenv/config';
22
import http from 'http';
33
import app from './src/app.js';
44
import connectDB from './src/config/db.js';
5-
import { start } from 'repl';
65

76
const PORT = process.env.PORT || 5000;
87
const NODE_ENV = process.env.NODE_ENV || 'development';
@@ -35,35 +34,39 @@ const startServer = async() => {
3534

3635
startServer();
3736

38-
process.on("unhandledRejection", (err) => {
39-
console.error("Unhandled Rejection: ", err);
40-
shutdownGracefully();
41-
});
42-
43-
process.on("uncaughtException", (err) => {
44-
console.error("Uncaught Exception: ", err);
45-
shutdownGracefully();
46-
});
47-
48-
const shutdownGracefully = () => {
37+
const shutdownGracefully = (exitCode = 0) => {
4938
if (server) {
5039
server.close(() => {
51-
console.log("Server closed grecefully");
52-
process.exit(1);
40+
console.log("Server closed gracefully");
41+
process.exit(exitCode);
5342
});
43+
44+
setTimeout(() => {
45+
console.error("Forced shutdown after timeout");
46+
process.exit(exitCode);
47+
}, 10000).unref();
5448
}
5549
else {
56-
process.exit(1);
50+
process.exit(exitCode);
5751
}
5852
};
5953

54+
process.on("unhandledRejection", (err) => {
55+
console.error("Unhandled Rejection: ", err);
56+
shutdownGracefully(1);
57+
});
58+
59+
process.on("uncaughtException", (err) => {
60+
console.error("Uncaught Exception: ", err);
61+
shutdownGracefully(1);
62+
});
63+
6064
process.on("SIGTERM", () => {
6165
console.log("SIGTERM received. Shutting down...");
6266
shutdownGracefully();
6367
});
6468

6569
process.on("SIGINT", () => {
66-
console.log("SIGINT reveiced. Shutting down...");
70+
console.log("SIGINT received. Shutting down...");
6771
shutdownGracefully();
68-
});
69-
72+
});

0 commit comments

Comments
 (0)