-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (24 loc) · 674 Bytes
/
app.js
File metadata and controls
30 lines (24 loc) · 674 Bytes
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
// Module Dependencies
const express = require('express');
// Initalizes the express 'app' variable
const app = express();
// Attaches the routes to the 'app'.
const routes = require('./routes/index');
app.use('/', routes);
// Catches 404 and forwards to error handlers
app.use((req, res, next) => {
let err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
app.use((err, req, res, next) => {
// sends the error in json
res.status(err.status || 500);
res.json({
message: err.message,
error: req.app.get('env') === 'development' ? err : {}
});
});
// Exports all app settings
module.exports = app;