-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
39 lines (33 loc) · 1014 Bytes
/
server.ts
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
const dotenv = require('dotenv');
dotenv.config({path: './config.env'});
const appExpress = require('./app');
const mongoose = require('mongoose');
mongoose.connect(process.env.DATABASE_LOCAL, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true
}).then(() => {
console.log('mdb local')
}).catch((error: any) => {
console.log('Error connecting to database: ', error);
return process.exit(1);
});
const port = process.env.PORT;
const server = appExpress.listen(port, () => {
console.log(`Listening on ${port}...`)
});
process.on('unhandledRejection', (error: any) => {
console.log('Unhandled rejection. The app is shutting down.');
console.log(error.name);
server.close(() => {
process.exit(1);
});
});
process.on('uncaughtException', (error: any) => {
console.log('Uncaught exception. The app is shutting down.');
console.log(error.name);
server.close(() => {
process.exit(1);
});
});