-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (31 loc) · 904 Bytes
/
app.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
const express = require('express');
const mongoose = require('mongoose');
const userRoute = require('./src/routes/users');
const parkingRoute = require('./src/routes/parkings');
const app = express();
var cors = require('cors');
require('dotenv').config();
app.use(cors());
const init = async () => {
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Connected to Cluster Atlas MongoDB
const uri = `${process.env.MONGODB_URI}?retryWrites=true&w=majority`;
try {
await mongoose
.connect(uri, {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
})
}
catch (err) {
console.error('Error connecting to mongo', err);
}
// -----------------------------------
app.use('/', userRoute);
app.use('/parkings', parkingRoute)
return app
}
module.exports = init