-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (41 loc) · 1.28 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
49
50
51
52
53
require('express-async-errors');
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const morgan = require('morgan');
const helmet = require('helmet');
const compression = require('compression');
const routes = require('./routes/routes');
const config = require('config');
const winston =require('winston');
process.on('uncaughtException',(ex)=>{
console.log(`Ran into an error ${ex}`);
winston.error(ex.message,ex);
});
process.on('unhandledRejection',(ex) => {
console.log(`Ran into an error ${ex}`);
winston.error(ex.message,ex);
});
winston.add(new winston.transports.File({filename:'logFile.log'}));
const PORT = process.env.PORT || 4000;
const app = express();
if(!config.get('db')){
console.log('Database Credentials not defined');
process.exit(1);
}
require('./models/database/dbContext')();
if(!config.get('jwtPrivateKey')){
console.log('JSON Web Token Secret not defined');
process.exit(1);
}
app.use(cors());
app.use(morgan('combined'));
app.use(helmet());
app.use(compression());
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
routes(app);
const server = app.listen(PORT,() =>{
console.log(`Now Listening on ${PORT}`);
});
module.exports = server;