Huligan Huligan - 5 months ago 10
Node.js Question

How to transfer params to GET method in Express?

I have the following URL:

'http://localhost/track/' + id + '/fromdate/' + date_start + '/todate/' + date_end


And there is handler in Node.js part:

app.get('/track/:id/fromdate/:fromdate/todate/:todate', function(req, res){
alert(req.params.fromdate);
});


Why I can not get
req.params.fromdate

Answer

can you try this please:

'http://localhost/track/' + encodeURIComponent(id) + '/fromdate/' + encodeURIComponent(date_start)+ '/todate/' + encodeURIComponent(date_end)

when you are making a get request, you should turn the parameters into encoded URI components like in the example i give