-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (30 loc) · 863 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
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const { applications } = require('./routes')
const { Application } = require('./models')
const port = process.env.PORT || 3030
let app = express()
.use(cors())
.use(bodyParser.urlencoded({ extended: true }))
.use(bodyParser.json())
// Our routes
.use(applications)
// catch 404 and forward to error handler, actuall error
.use((req, res, next) => {
const err = new Error('Not Found')
err.status = 404
next(err)
})
// final error handler
.use((err, req, res, next) => {
res.status(err.status || 500)
res.send({ //send an object
//only print full errors in development
message: err.message,
error: err
})
})
.listen(port, () => {
console.log(`Server is listening on port ${port}`)
})