-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
34 lines (29 loc) · 864 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
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const morgan = require('morgan');
const helmet = require('helmet');
const logger = require('./src/utils/logger');
const { connectToServer } = require('./src/db/conn');
const app = express();
const appRoutes = require('./src/routes');
const errorHandler = require('./src/middlewares/errorHandler');
app.disable('x-powered-by');
app.use(express.json());
app.use(morgan('combined'));
app.use(cors());
app.use(helmet());
app.use(appRoutes);
app.use(errorHandler);
const PORT = process.env.SERVER_PORT || 3001;
(async () => {
try {
await connectToServer();
app.listen(PORT, '0.0.0.0', () => {
logger.info(`Server is running on port: ${PORT}`);
});
} catch (err) {
logger.error(err);
process.exit();
}
})()