- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
Latest commit
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
constapp=require("./app");
constmongoose=require("mongoose");
constdotenv=require("dotenv");
process.on("uncaughtException",(err)=>{
console.log(err.name,err.message);
console.log("UNHANDLED EXCEPTION 🔔");
process.exit(1);
});
dotenv.config({path: "./config.env"});
constdatabaseConnection=process.env.DATABASE.replace(
"<password>",
process.env.DATABASE_PASSWORD
);
// Connecting to MongoDB
mongoose
.connect(databaseConnection,{
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(()=>console.log("MongoDB Connected"));
constport=3000;
// Logging the current environment mode.
console.log(process.env.NODE_ENV);
// Starting the server and logging a message on successful startup.
constserver=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);
});
});