-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (22 loc) · 857 Bytes
/
Copy pathapp.js
File metadata and controls
31 lines (22 loc) · 857 Bytes
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
require('./config/config');
require('./models/db');
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
var rtsIndex = require('./routes/index.router');
var app = express();
//middleware
app.use(bodyParser.json());
app.use(cors());
app.use('/api', rtsIndex);
//error handler
app.use((err, req,res,next) =>{
if(err.name === 'ValidationError'){
var valErrors = [];
Object.keys(err.errors).forEach(key => valErrors.push(err.errors[key].message));
res.status(422).send(valErrors)
}
})
app.listen(process.env.PORT, () => { console.log(`Server started at posrt ${process.env.PORT} `)})
// mongodb+srv://Balgopal:<password>@cluster0-cwoke.gcp.mongodb.net/test?retryWrites=true&w=majority
// "MONGODB_URI": "mongodb://xxxx/MEANStackDB"