forked from jason-fox/csv-to-json
-
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) · 728 Bytes
/
app.js
File metadata and controls
30 lines (24 loc) · 728 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
const express = require('express');
const Router = require('./routes/routes');
const db = require('./lib/dbConn');
const app = express();
const path = require('path');
const Status = require('http-status-codes');
global.__basedir = __dirname;
db.connect();
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use('/', Router);
app.use(express.static(path.join(__dirname, 'public')));
// catch 404 and forward to error handler
app.use(function (req, res) {
res.status(Status.NOT_FOUND);
res.json();
});
// error handler
app.use(function (err, req, res) {
console.error(err);
res.status(err.status || Status.INTERNAL_SERVER_ERROR);
res.json({ err });
});
module.exports = app;