-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
34 lines (33 loc) · 1.01 KB
/
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
const dotenv = require('dotenv');
dotenv.config({ path: './config.env' });
const mongoose = require('mongoose');
process.on('uncaughtException', (err) => {
console.log(`UNHANDLED EXPECTION 💣💣 ${err.message}`);
console.log(err.name, err.stack);
process.exit(1);
});
const app = require('./app');
//////////////////////////////////////////
//mongoose connection
let now = new Date().getSeconds();
mongoose.connect(process.env.DATABASE).then(() => {
//console.log(conn.connection)
console.log(
`connected successfully in ${Math.abs(
new Date().getSeconds() - now
)} seconds`
);
});
//////////////////////////////////////////
// server-Listening
const server = app.listen(process.env.PORT, () => {
console.log(`server started on port : ${process.env.PORT} ...`);
});
//////////////////////////////////////////
process.on('unhandledRejection', (err) => {
console.log(err.name, err.message);
console.log(`unhandled promise rejection 💣💣`);
server.close(() => {
process.exit(1);
});
});