-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (30 loc) · 1.25 KB
/
server.js
File metadata and controls
42 lines (30 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import TCPServer from "./src/server/TCPServer.js";
process.on("uncaughtException", async (err) => {
console.log("UNCAUGHT EXCEPTION! 💥 Shutting down...");
console.log(err.name, err.message);
await safeClose(1);
});
const host = process.env.host || "0.0.0.0";
const port = parseInt(process.env.port, 10) || 8000;
const server = new TCPServer(host, port);
console.log("╔════════════════════════════════════════════╗");
console.log("║ Key-Value Database Engine ║");
console.log("╚════════════════════════════════════════════╝\n");
await server.start();
process.on("SIGINT", async () => {
console.log("Shutting down server...");
await safeClose(0);
});
process.on("unhandledRejection", async (err) => {
console.log("UNHANDLED REJECTION! 💥 Shutting down...");
console.log(err.name, err.message);
await safeClose(1);
});
process.on("SIGTERM", async () => {
console.log("👋 SIGTERM RECEIVED. Shutting down gracefully");
await safeClose(0);
});
async function safeClose(exitCode = 1) {
await server.shutdown();
process.exit(exitCode);
}