Reputation: 3434
Im trying to get the value of the parameter passed in the URL with app.get like this:
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.get('/mytest/:id', function(req, res){
var idparam = req.params.id;
var idquery = req.query.id;
var idbody = req.body.id;
res.send(idparam);
});
So when I pass localhost:3000/mytest/id=266, i get: id=266
instead of just 266
. And get undefined with idquery
and idbody
.
I only want to get the value of the id. What am I doing wrong?
Upvotes: 0
Views: 76
Reputation: 1010
You should use it like this localhost:3000/mytest/266
instead of localhost:3000/mytest/id=266
It will be resolved as req.params.id
Upvotes: 1
Reputation: 1870
Make a request like localhost:3000/mytest/266
where 266 will be matched as id param
Upvotes: 1