Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the request method type in `app.all()`?

Tags:

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.

like image 600
ijse Avatar asked Dec 16 '12 09:12

ijse


People also ask

What is the app use () method doing?

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.

What is the difference between app use and app get?

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.

What is get method in Express?

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 .


1 Answers

I've found it! req.method will do, so easy!

like image 149
ijse Avatar answered Oct 11 '22 17:10

ijse