-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (36 loc) · 1023 Bytes
/
index.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
const express = require('express');
const bodyParser = require('body-parser');
const helmet = require('helmet');
const cors = require('cors');
const mongoose = require('mongoose');
const morgan = require('morgan');
const errors = require('./api/middlewares/errors');
const {
DATABASE_PASSWORD,
DATABASE_URI,
DATABASE_USER,
NODE_ENV,
PORT
} = require('./config');
const port = parseInt(PORT, 10) || 8080;
const dev = NODE_ENV !== 'production';
mongoose
.connect(
`mongodb://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_URI}`,
{ useNewUrlParser: true }
)
.then(() => {
console.log('MongoDB Connected...');
require('./api/lib/cart');
})
.catch(err => console.log(`Error ${err}`));
const app = express();
app.use(cors());
app.use(helmet());
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
require('./api/routes')(app);
app.use(errors);
app.listen(port, () => console.log(`listening on port ${port}`));
module.exports = app;