-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (35 loc) 路 1.08 KB
/
Copy pathserver.js
File metadata and controls
43 lines (35 loc) 路 1.08 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
43
const app = require("./app");
const mongoose = require("mongoose");
const dotenv = require("dotenv");
process.on("uncaughtException", (err) => {
console.log(err.name, err.message);
console.log("UNHANDLED EXCEPTION 馃敂");
process.exit(1);
});
dotenv.config({ path: "./config.env" });
const databaseConnection = process.env.DATABASE.replace(
"<password>",
process.env.DATABASE_PASSWORD
);
// Connecting to MongoDB
mongoose
.connect(databaseConnection, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("MongoDB Connected"));
const port = 3000;
// Logging the current environment mode.
console.log(process.env.NODE_ENV);
// Starting the server and logging a message on successful startup.
const server = app.listen(port, () => {
console.log(`Server Started on : ${port}`);
});
// Handling unhandled promise rejections and gracefully closing the server on error.
process.on("unhandledRejection", (err) => {
console.log(err.name, err.message);
console.log("UNHANDLED REJECTION 馃敂");
server.close(() => {
process.exit(1);
});
});