-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (29 loc) · 823 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
const path = require('path');
const express = require('express');
const app = express();
const morgan = require('morgan');
require('./database');
const routing = require('./routes');
const errorHandler = require('errorhandler');
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(morgan('tiny'));
app.use(routing);
if (process.env.NODE_ENV === 'development') {
app.use(errorHandler());
}
app.use((err, req, res, next) => {
const env = process.env.NODE_ENV;
if (env === 'production') {
res.status(500).render('error', {
error: {
code: err.code || 500,
message: err.message
}
});
}
});
app.listen(3000);