I need to create url for get which is going to accept array, how in node.js/express extract array from request ? I need to pass array with names which parametes I need to ba
If you want to pass an array from url parameters, you need to follow the bellow example:
Url example:
https://website.com/example?myarray[]=136129&myarray[]=137794&myarray[]=137792
To retrieve it from express:
console.log(req.query.myarray)
[ '136129', '137794', '137792' ]
Express exposes the query parameter as an array when it is repeated more than once in the request URL:
app.get('/', function(req, res, next) {
console.log(req.query.a)
res.send(200)
}
GET /?a=x&a=y&a=z:
// query.a is ['x', 'y', 'z']
Same applies for req.body in other methods.