Skip to content
Advertisement

req.query returns nothing

Trying to get variable from http://localhost:3000/categories/subcategories?category_id=13 but req.query returns empty result.

Is this possibly a problem with the way I’ve set up my server?

Advertisement

Answer

See how you are passing the data , directly entering the data or from another URL you are passing the data. Ensuring you are not sending data via req.body. Ref :

Empty req.query on ExpressJS

or check res.send({category_id}) . Try printing res.send({“category_id”: category_id}) . or see console.log(JSON.stringify(req.query))

Or Extract Query Parameters Without Express

https://stackabuse.com/get-query-strings-and-parameters-in-express-js/

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement