generated from GDGVIT/node-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (33 loc) · 950 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
36
37
const express = require('express');
const compression = require('compression');
const mongoose = require('mongoose');
const cors = require('cors');
const morgan = require('./logging/morgan');
const routes = require('./routes/index');
const logger = require('./logging/logger');
const stateWiseRoutes = require('./routes/stateWise');
const app = express();
// Middlewares
app.use(express.json({limit: "100mb"}));
app.use(compression());
app.use(cors());
require('dotenv').config();
mongoose.connect(
process.env.DB_CONNECTION, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
})
.then(() => {
logger.info('Connected to DB');
})
.catch((err) => {
logger.error(err);
process.exit(2);
});
// Logging
app.use(morgan);
// Mount routes
app.use('/api/patients', routes);
app.use('/api/statewise', stateWiseRoutes);
module.exports = app;