Tell us what’s happening:
Describe your issue in detail here.
So I passed the “Implement a root level request logger middleware” with the code below. But when I read my logs the output is get. Why is req.method GET when I did not use that command at all in my middleware?
So I see that “Bind application-level middleware to an instance of the app object by using the app.use() and app.METHOD() functions, where METHOD is the HTTP method of the request that the middleware function handles (such as GET, PUT, or POST) in lowercase.” So my understanding from this is that use is not an HTTP method. Maybe I should be focusing more on what HTTP methods are?
Then here “The function is executed for any type of HTTP request on the /user/:id path.”
It seems to say that the use method in express gets called for any type of HTTP request. So is it that by going to a website I’m sending a get request to my server? How would I send a post or put request to get the req.method to output something else? Can a user do that or are those only backend terms?
The handler function in an app.method (get/post/whatever) is technically part of the middleware system, they are often called a controller. You can chain middleware.
function someMiddleware(req, res, next) {
...do something
next();
}
app.get('/', someMiddleware, (req, res) => {
...handle get
})
The someMiddleware will only run on that specific method and path (before the controller). The controller doesn’t have to be inline it can be defined like the middleware.