-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (29 loc) · 938 Bytes
/
index.js
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
import app from "./app.js";
import dotenv from "dotenv";
import connectdb from "./config/db.js";
// Uncaught Exception
process.on("uncaughtException", (err) => {
console.log(`Error: ${err.message}`);
console.log("Shutting down server due to Uncaught Exception.");
server.close(() => {
process.exit(1);
});
});
// config for all the .env variables
dotenv.config({ path: "./config/config.env" });
// conneting to the database
connectdb();
// PORT variable from .env file
const port = process.env.PORT;
// 'server' variable made so that we can use some methods on it
const server = app.listen(port, () => {
console.log(`Server is listening at http://localhost:${port}`);
});
// Unhandled Promise Rejections
process.on("unhandledRejection", (err) => {
console.log(`Error: ${err.message}`);
console.log("Shutting down server due to unhandled promise rejection.");
server.close(() => {
process.exit(1);
});
});