Parsing query array with request and receiving with express

Viewed 4000

I have an issue sending and receiving query params with express and request.

Request side:

const request = require('request');
request({url: 'http://localhost', json: true, qs: {id: [1,2,3,4]}})

Request sends a request like that to my server:

http://localhost/?id%5B0%5D=1&id%5B1%5D=2&id%5B2%5D=3&id%5B3%5D=4

Then when I receive my result using express

app.get('/', (req, res, next) => {
    console.log(req.query);
})

I have

{id: {0: 1, 1: 2, 2: 3, 3: 4}}

I would like to have

{id: [1,2,3,4]}

If I manually send a request using this url it works

http://localhost/?id=1&id=2&id=3&id=4

So I do not understand if the error comes from request witch have issues parsing my array or express having problems parsing my query

2 Answers
Related