Home > Enterprise >  How to access information in a URL request with express?
How to access information in a URL request with express?

Time:12-11

how can I extraxt the location value of the following request with express?

http://localhost:3000/campgrounds?location=Austin

CodePudding user response:

Use req.query.*.

app.get("/campgrounds", function(req, res) {
   res.status(200).send(req.query.location); 
});

Note: this won't work if your user doesn't input the location query.

CodePudding user response:

In the url http://localhost:3000/campgrounds?location=Austin

location is a query parameter and Austin is the value of the query parameter.

In express, get the value of the query parameter by invoking:

req.query.location

see https://expressjs.com/en/api.html#req.query

  • Related