0

I am trying to get query parameters through a POST request and it doesn't seem to receive them.

app.use(bodyParser.urlencoded({ extended: false }));

app.post('/pubs/:id/submit', function (req, res, next) {

    console.log("query: " + JSON.stringify(req.query)) //prints {}

I have tried sending the request through Postman and curl and the request is properly formed.

bezzoon
  • 1,755
  • 4
  • 24
  • 52

1 Answers1

0

Use body-parser to parse the body.

var bodyParser=require('body-parser');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended: false
}));

Example#1 by parameters

POST http://localhost:3000/hello/id/123/access_token/1234556ccc/name/hola

console.log(JSON.stringify(req.params))

Example#2 by query

POST http://localhost:3000/hello?text=abc&access_token=1234556ccc&name=hola

`console.log(JSON.stringify(req.query))`
abdulbarik
  • 6,101
  • 5
  • 38
  • 59