Reputation: 1303
I'm working on a nodejs project express application. My route looks something like this:
router.get('/observe/:fileName', function(res, req){
var reqFileName = req.params.fileName;
console.log("GET /observe/" + reqFileName);
res.end();
}
The problem is that if I do a GET request on localhost/observe/myFile
the variable reqFileName
is undefined because req.params.fileName
is undefined. But inspecting(using node-inspector) the req
I can see that the req
has a property called req
that has params
. so req.req.params.fileName
will give my parameter value. Is this normal ?
Upvotes: 3
Views: 1587
Reputation: 8141
You've got res
and req
backwards. Try this:
router.get('/observe/:fileName', function(req, res){
var reqFileName = req.params.fileName;
console.log("GET /observe/" + reqFileName);
res.end();
}
Upvotes: 8