-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (22 loc) · 817 Bytes
/
app.js
File metadata and controls
32 lines (22 loc) · 817 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
const express = require("express");
const app = express();
const authorRouter = require("./routes/authorRouter")
const bookRouter = require("./routes/bookRouter")
const indexRouter = require("./routes/indexRouter")
// i guess these are the middleware funcs?
app.use("/authors", authorRouter)
app.use("/books", bookRouter)
app.use("/", indexRouter)
// Every thrown error in the application or the previous middleware function calling `next` with an error as an argument will eventually go to this middleware function
// you need to include 4 params even though they are not used!
app.use((err, req, res, next) => {
console.error(err);
res.status(500).send(err);
});
const PORT = 3000;
app.listen(PORT, (error) => {
if (error) {
throw error
}
console.log(`server listening on port: ${PORT}`)
})