Skip to content

Commit adef9c7

Browse files
Edit middleware example to include more
1 parent a3ea367 commit adef9c7

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

middleware_example.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const express = require("express");
22
const app = express();
3+
const PORT = 3000;
34

45
app.use(function(req, res, next) {
56
console.log("common middleware function was called!");
@@ -11,14 +12,26 @@ app.use("/users", function(req, res, next) {
1112
next();
1213
});
1314

15+
app.post("/users", function(req, res, next) {
16+
console.log("second middleware function for /users was called!");
17+
next();
18+
});
19+
20+
app.get("/users", function(req, res, next) {
21+
console.log("third middleware function for /users was called!");
22+
next();
23+
});
24+
1425
app.get("/users", function(req, res) {
26+
console.log("users list was shown");
1527
res.send("Here is a list of users:....");
1628
});
1729

1830
app.get("/books", function(req, res) {
31+
console.log("books list was shown");
1932
res.send("Here is a list of books:....");
2033
});
2134

22-
const server = app.listen(3000, function() {
23-
console.log("Application started....");
35+
const server = app.listen(PORT, () => {
36+
console.log(`Server running at http://localhost:${PORT}`);
2437
});

0 commit comments

Comments
 (0)