forked from aghaffar570/recipes-api-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
21 lines (15 loc) · 653 Bytes
/
Copy pathapp.js
File metadata and controls
21 lines (15 loc) · 653 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const express = require("express");
const morgan = require("morgan");
const cors = require("cors");
const apiRouter = require("./api");
const app = express();
app.use(express.json()); // parses JSON bodies into req.body
app.use(morgan("dev")); // logs every request to the terminal
app.use(cors()); // allows a frontend on a different port to make requests here
app.use("/api", apiRouter); // every route below lives under /api
// 4 params (not 3) is how Express knows this is the error handler
app.use((err, req, res, next) => {
console.error(err);
res.sendStatus(500);
});
app.listen(8080, () => console.log("Server running on port 8080"));