-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
43 lines (37 loc) · 1.17 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
38
39
40
41
42
43
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');
const databaseConnection = require('./db-connect.json');
const dotenv = require('dotenv');
dotenv.config();
let app = express();
const PORT = process.env.PORT || 8090;
const MONGO_URI = databaseConnection.url;
const mongoConnection = mongoose.connection;
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
mongoose.connect(MONGO_URI, {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
});
require('./plugins/delivery-services/index')(app);
require('./plugins/deliveries/index')(app);
app.route('/').get((req, res) => {
res.send('<h4>Welcome to ShopaFy Deliver API by REG_WE_14</h4>');
});
mongoConnection.once("open", (error) => {
if (error) {
return console.log('Cannot connect to MongoDB');
}
console.log('MongoDB Connection Success');
})
app.listen(PORT, error => {
if (error) {
return console.log(`Cannot connect the the server using PORT ${PORT}`);
}
console.log(`Successfully connected to server on PORT ${PORT}`);
});