-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
42 lines (27 loc) · 829 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
35
36
37
38
39
40
41
const app = require("express")();
const cors = require('cors');
require("dotenv").config();
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
mongoose.Promise = global.Promise;
app.use(cors());
var port = process.env.PORT || 6000;
mongoose.Promise = global.Promise;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
var v1 = require('./api/routes');
app.use('/api/v1', v1.router);
app.use(function(req, res) {
res.status(404).send({url: req.originalUrl + ' not found'})
});
mongoose.connect(process.env.DATABASE, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true
}).then(()=>{
app.listen(port, () => {
console.log(`API server started on database: ${port}`);
});
}).catch(()=>{
console.log('Error');
})