-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
29 lines (27 loc) · 828 Bytes
/
server.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
const dotenv = require('dotenv');
dotenv.config({ path: './config.env' });
const http = require('http');
const app = require('./app');
const config = require('./utils/config');
const mongoose = require('mongoose');
const server = http.createServer(app);
console.log('Starting app..');
console.log('Waiting for connection to MongoDB');
mongoose
.connect(config.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
})
.then(() => {
console.log('Connected to MongoDB!');
console.log('Starting webserver..');
server.listen(config.PORT, () => {
console.log(`Server is running on port ${config.PORT}`);
});
})
.catch(() => {
console.log('Could not connect to MongoDB server! Shutting down...');
process.exit(1);
});