-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
30 lines (23 loc) · 764 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
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/ninjago');
mongoose.Promise = global.Promise;
//set up static files
app.use(express.static('public'));
// use body-parser middleware
app.use(bodyParser.json());
// initialize routes
app.use('/api', require('./routes/api'));
// error handling middleware
app.use(function(err, req, res, next){
console.log(err); // to see properties of message in our console
res.status(422).send({error: err.message});
});
// listen for requests
app.listen(process.env.port || 4000, function(){
console.log('now listening for requests');
});