-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.js
44 lines (32 loc) · 1.03 KB
/
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
36
37
38
39
40
41
42
43
44
/* eslint-disable no-console */
const cors = require('cors');
const _ = require('lodash');
const express = require('express');
const BodyParser = require('body-parser');
const mongoClient = require('./source/database/config');
const walletRoute = require('./source/routes/WalletRoute');
const commonRoute = require('./source/routes/CommonRoute');
const { MONGODB_CONNECT_ERROR } = require('./source/variables/errors');
const app = express();
app.use(cors());
app.use(BodyParser.json());
app.use(BodyParser.urlencoded({ extended: true }));
async function startMongoDb() {
try {
await mongoClient.connect();
} catch (error) {
console.log(MONGODB_CONNECT_ERROR, error);
}
}
async function startExpress() {
const port = process.env.PORT || 5000;
const portStatus = `Listening on port ${port}`;
app.listen(port);
console.log(portStatus);
app.get('/', (req, res) => res.json({ msg: 'tugkan API service' }));
// Routes
app.use('/wallet', walletRoute);
app.use('/common', commonRoute);
}
startMongoDb();
startExpress();