With expressjs, app.all()
handles all request, and now I want the request method type(get
or post
) in app.all()
, but I don't know how to do this. I've been search in expressjs document, but didn't find anything valuable.
Thanks for your answer.
The app. use() function is used to mount the specified middleware function(s) at the path which is being specified. It is mostly used to set up middleware for your application.
app. get is called when the HTTP method is set to GET , whereas app. use is called regardless of the HTTP method, and therefore defines a layer which is on top of all the other RESTful types which the express packages gives you access to.
Express' app. get() function lets you define a route handler for GET requests to a given URL. For example, the below code registers a route handler that Express will call when it receives an HTTP GET request to /test .
I've found it! req.method will do, so easy!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With