Parse numbers in ExpressJS requests.
Installation
npm i num-parser --save
Usage
The module will parse all numbers in req.query
, req.params
, and req.body
.
Also works with floating points.
To work with req.body
you need to add after body-parser:
const bodyParser = const numParser = appapp // ?a=1&b[c]=tw0&b[d]=3.5app
NOTE: I've had problems having it as a global middleware to work with req.params
. If it's not working for you, try putting the middleware in for each route:
// ?a=1&b[c]=tw0&b[d]=3.5app