-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (25 loc) · 876 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
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
// Set up express app
const app = express();
// Connect to mongodb
mongoose.connect('mongodb://localhost:27017/ninjago', { useNewUrlParser: true });
mongoose.Promise = global.Promise;
mongoose.set('useFindAndModify', false);
// Using static folder
app.use(express.static('public'));
app.use(bodyParser.json({ type: 'application/*+json' }))
//app.use(bodyParser.json());
// Initilize routes
app.use('/api', require('./routes/app'));
// Error handling middleware
app.use(function(err, req, res, next) {
console.log(err);
res.status(422).send({ error: err.mongoose });
console.log("Error list console");
});
// listen for request
app.listen(process.env.port || 4000, function() {
console.log('Server is running on port 4000');
});