Skip to content

Commit 6b3fc39

Browse files
Add middleware example 2 for arrow function and color query
1 parent e46b154 commit 6b3fc39

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

middleware_example_2.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const express = require("express");
2+
const app = express();
3+
const PORT = 3000;
4+
5+
const arrowFunction = (req, res, next) => {
6+
console.log("I am an arrow function!");
7+
next();
8+
};
9+
10+
app.use(arrowFunction);
11+
12+
const checkColor = () => {
13+
return (req, res, next) => {
14+
if (req.query.color) {
15+
res.send("I have blue!");
16+
} else {
17+
next();
18+
}
19+
};
20+
};
21+
22+
app.use(checkColor());
23+
24+
app.get("/users", function(req, res) {
25+
console.log("users list was shown");
26+
res.send("Here is a list of users:....");
27+
});
28+
29+
app.get("/books", function(req, res) {
30+
console.log("books list was shown");
31+
res.send("Here is a list of books:....");
32+
});
33+
34+
const server = app.listen(PORT, () => {
35+
console.log(`Server running at http://localhost:${PORT}`);
36+
});

0 commit comments

Comments
 (0)