-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
44 lines (40 loc) · 1.26 KB
/
server.js
File metadata and controls
44 lines (40 loc) · 1.26 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
44
//database configuration
// error handeling
// environment variables
const mongoose = require('mongoose');
const dotenv = require('dotenv');
const port = process.env.PORT || 3000;
// basically we are listening the unhandle promise for async codes
process.on('unhandledRejection', (err) => {
// listening to an event
console.log(err);
console.log('Unhandle Rejection: 🌟 Shutting Down...');
process.exit(1);
// first we close the server. we give time to server to finish the request whatever it is handeling
});
process.on('uncaughtException', (err) => {
console.log(err);
console.log('Unhandle Exception: 🌟 Shutting Down...');
//server.close(); // first we close the server. we give time to server to finish the request whatever it is handeling
process.exit(1);
});
dotenv.config({ path: './config.env' });
const app = require('./app');
//console.log(process.env);
const DB = process.env.DATABASE.replace(
'<PASSWORD>',
process.env.DATABASE_PASSWORD
);
mongoose
.connect(DB, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
})
.then((con) => {
//console.log(con.connections);
console.log('DB Connection Established');
});
const server = app.listen(port, () => {
console.log(`App running on ${port}...`);
});