Expressjs req.params is undefined but req.req.params are defined

I am working on a core nodejs 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, if I make a GET request for localhost/observe/myFile

, the variable reqFileName

is undefined because it req.params.fileName

is undefined. But by checking (using node-inspector) req

I can see what req

has a property req

that has params

. so req.req.params.fileName

will give the value of my parameter. This is normal?

+3


source to share


1 answer


You have res

and req

back. Try the following:



router.get('/observe/:fileName', function(req, res){

    var reqFileName = req.params.fileName;

    console.log("GET /observe/" + reqFileName);
    res.end();

}

      

+7


source







All Articles