-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
42 lines (31 loc) · 792 Bytes
/
app.js
File metadata and controls
42 lines (31 loc) · 792 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
31
32
33
34
35
36
37
38
39
40
41
42
import express from 'express';
import mongoose from 'mongoose';
import bodyParser from 'body-parser';
import routes from './routes/index.js';
const app = express();
/**
* Connect to the database
*/
mongoose.connect('mongodb://localhost:27017/notesdb',{ useNewUrlParser: true, useUnifiedTopology: true });
/**
* Middleware
*/
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// catch 400
app.use((err, req, res, next) => {
console.log(err.stack);
res.status(400).send(`Error: ${res.originUrl} not found`);
next();
});
// catch 500
app.use((err, req, res, next) => {
console.log(err.stack)
res.status(500).send(`Error: ${err}`);
next();
});
/**
* Register the routes
*/
routes(app);
export default app;