-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
37 lines (34 loc) · 1.1 KB
/
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
30
31
32
33
34
35
36
37
const app = require('./app');
const mongoose = require('mongoose');
const config = require('./config/keys.config');
const start = async () => {
try {
await mongoose
.connect(config.mongoURI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
})
.then(() =>
console.log(
'MongoDB database has been successfully connected. Expecting server to start ... ',
),
)
.catch((error) =>
console.log(
'Warning! An error occurred while connecting to the MongoDB database. Error: ' +
error,
),
);
app.listen(config.port, () => {
console.log(`Server has been started on port ${config.port}...`);
});
} catch (error) {
console.log(
'Warning! An error occurred while starting the server. Error: ' + error.message,
);
process.exit(1);
}
};
start();