-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (28 loc) · 882 Bytes
/
Copy pathserver.js
File metadata and controls
33 lines (28 loc) · 882 Bytes
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
import app from './app.js';
import dotenv from 'dotenv';
import mongoose from 'mongoose';
process.on('uncaughtException', error => {
console.log('UNCAUGHT EXCEPTION! Shutting down...');
console.log(error.name, error.message);
process.exit(1);
});
dotenv.config({ path: './.env' });
const dbConnectionString = process.env.DATABASE.replace(
'PASSWORD',
process.env.DATABASE_PASSWORD,
);
mongoose.connect(dbConnectionString).then(() => {
console.log('DB connection successful!');
});
// ------------- 4) Start Server -------------
const port = process.env.PORT || 3000;
const server = app.listen(port, () => {
console.log(`App running at http://localhost:${port}`);
});
process.on('unhandledRejection', error => {
console.log(error.name, error.message);
console.log('UNHANDLED REJECTION! Shutting down...');
server.close(() => {
process.exit(1);
});
});