-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (28 loc) · 1021 Bytes
/
server.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
const app = require("./app")
const dotenv = require("dotenv")
const connectDatabase = require("./config/database")
const cloudinary = require("cloudinary")
// handling uncaught Exception
process.on("uncaughtException",(err)=>{
console.log(`Error : ${err.message}`);
console.log(`shutting down the server due to uncaught expression`);
process.exit(1)
})
dotenv.config({path:"backend/config/config.env"})
connectDatabase();
cloudinary.config({
cloud_name : process.env.CLOUDINARY_NAME,
api_key : process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET
})
const server = app.listen(process.env.PORT, ()=>{
console.log(`server is running on http://localhost:${process.env.PORT}`);
})
// unhandled promise rejection
process.on("unhandledRejection",(err)=>{
console.log(`Error: ${err.message}`);
console.log('shutting down the server due to unhandled promise rejection');
server.close(()=>{
process.exit(1)
})
})