-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
37 lines (27 loc) · 980 Bytes
/
index.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
const express = require("express");
const mongoose = require("mongoose");
const tasksRouter = require('./routes/tasksRouter')
const globalErrorHandler = require('./utils/globalErrorHandler')
const app = require('./app');
const dotenv = require('dotenv');
dotenv.config({ path: './config.env' });
process.on('uncaughtException', err => {
console.log(err.name , err.message);
console.log('Unhandled Exception, shutting down');
process.exit(1);
});
const DB = process.env.DATABASE.replace('<password>', process.env.DATABASE_PASS);
mongoose.connect(DB).then(con => {
console.log('db connection succesfful');
})
const port = process.env.PORT || 8000;
const server = app.listen(port, () => {
console.log(`CORS-enabled App running on port ${port}...`);
});
process.on('unhandledRejection', err => {
console.log(err.name , err.message);
console.log('Unhandled Rejection, shutting down');
server.close(() => {
process.exit(1);
});
});