Skip to content

app.param() Error when trying to validate parameters. #1263

@reggi

Description

@reggi

I was reading up in the API Reference under app.param() and I was interested in using it "…to effectively validate parameters, or also parse them to provide capture groups…". When I copy and paste the code example in it logs an error. I'm running express 3.0.0beta7

Code:

    app.param('range', /^(\w+)\.\.(\w+)?$/);

    app.get('/range/:range', function(req, res){
      var range = req.params.range;
      res.send('from ' + range[1] + ' to ' + range[2]);
    });

Error:

/Users/thomas/Desktop/node/platform/node_modules/express/lib/router/index.js:67
    throw new Error('invalid param() call for ' + name + ', got ' + fn);
          ^
Error: invalid param() call for range, got /^(\w+)\.\.(\w+)?$/
    at Router.param (/Users/thomas/Desktop/node/platform/node_modules/express/lib/router/index.js:67:11)
    at app.param (/Users/thomas/Desktop/node/platform/node_modules/express/lib/application.js:232:20)
    at Array.forEach (native)
    at Function.app.param (/Users/thomas/Desktop/node/platform/node_modules/express/lib/application.js:231:9)
    at Object.<anonymous> (/Users/thomas/Desktop/node/platform/app.js:47:5)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions