Reputation: 2787
Now am converting my php website to express js. There are lot pf script in my front end. All these script generate link like this page.php?id=10&something=anything. In express js, I can catch if the url like this page.php?/10/anything**. Is there any method to catch variable from url like page.php?id=10&something=anything in express js?
Upvotes: 2
Views: 859
Reputation: 2167
You can get using the traditional Express way like "/myroute/id/:number" and also like this "myroute?id=:number"
First: change the route code if your route seems like this:
app.get('/user/:id', user.list);
to
app.get('/user/', user.list);
Inside your users.js change the behavior to get the params...
exports.list = function(req, res){
var id = req.query.id;
console.log("ID: " + id);
};
The secret to get the params as you want is "query" in req.query.id.
Upvotes: 1