-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (24 loc) · 892 Bytes
/
Copy pathserver.js
File metadata and controls
29 lines (24 loc) · 892 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
import dotenv from 'dotenv';
dotenv.config();
process.on('uncaughtException', (err) => {
console.log(err.name, err.message);
console.log('UNCAUGHT EXCEPTION! 💥 Shutting Down...');
process.exit(1);
});
import mongoose from 'mongoose';
import app from './app.js';
const { PORT, MONGO_USER, MONGO_PASSWORD, MONGO_IP, MONGO_PORT } = process.env;
const connection_URL = `mongodb://${MONGO_USER}:${MONGO_PASSWORD}@${MONGO_IP}:${MONGO_PORT}/?authSource=admin`;
mongoose.connect(connection_URL).then((con) => {
console.log('DB connection successful');
});
const server = app.listen(PORT, () => {
console.log(
`${process.env.NODE_ENV} server is started http://localhost:${PORT}`
);
});
process.on('unhandledRejection', (err) => {
console.log(err.name, err.message);
console.log('💥 UNHANDLED REJECTION! 💻 Shutting down...');
server.close(() => process.exit(1));
});