Somename Somename - 3 months ago 19
Node.js Question

How to get the exact value of id

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?

Answer Source

Make a request like localhost:3000/mytest/266 where 266 will be matched as id param