2.0.0 • Published 7 years ago

req-param v2.0.0

Weekly downloads
10
License
MIT
Repository
github
Last release
7 years ago

req.param()

npm install req-param

https://nodei.co/npm/req-param.png?downloads=true

The familiar req.param() for express, as it is implemented in express 3 and 4. This got deprecated in express 4, so in case you don't agree with the deprecation rationale, and want to lose the deprecation warnings, this is for you.

Usage

app.use( require('req-param') )

Functionality

Returns the value of param name when present. req.param(name [, defaultValue])

// ?name=tobi
req.param('name')
// => "tobi"

// POST name=tobi
req.param('name')
// => "tobi"

// /user/tobi for /user/:name
req.param('name')
// => "tobi"

Lookup is performed in the following order:

  • req.params
  • req.body
  • req.query

Optionally, you can specify defaultValue to set a default value if the parameter is not found in any of the request objects.