-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (39 loc) · 1.09 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
45
46
47
48
'use strict';
const dotenv = require('dotenv');
dotenv.config();
const express = require('express');
const app = express();
const path = require('path');
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, '/views'));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
require('./routers')(app);
app.use((err, req, res, next) => {
if (err.code && err.result && err.result.messages) {
res.status(err.code).json({
status: false,
...err,
});
} else {
const code = 500;
res.status(code).json({
code,
status: false,
message: 'Something went wrong!',
});
}
});
const run = async () => {
try {
const connectDb = require('./core/database/mongo');
await connectDb();
app.listen(process.env.PORT, async () =>
console.log(`Application runs on port ${process.env.PORT}`)
);
} catch (e) {
console.log('App has been crashed!');
console.log('INFO: Please check env variables to run app.');
}
};
run();