
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
micro-validate
Advanced tools
micro-validate is an utility that is being used to validate parameters, it uses the createError function of micro to throw (or return) an 409 HTTP error to the request made to the microservice.
cd my-micro-project/
npm install --save micro-validate
and add use the package like this:
const { parse } = require('url')
const validate = require('micro-validate')
module.exports = (req, res) => {
const { user, country } = parse(req.url, true).query
validate({ user, country })
return 'all ok!'
}
then you can just try the microservice validation by doing some request, here are some examples:
http://localhost:3000?user=fmiras&country=argentina => HTTP 200 'all ok!'
http://localhost:3000?user=someuser => HTTP 409 'The country parameter is missing'
The package just validates if the parameter is defined or not, but you can also setup your custom validator and you can also use a custom message (if not, it will keep using the same):
const { parse } = require('url')
const validate = require('micro-validate')
const validator = p => Number.isInteger(p)
module.exports = (req, res) => {
const { zip_code } = parse(req.url, true).query
validate({ zip_code }, validator, 'The parameter {param} is wrong')
return 'all ok!'
}
http://localhost:3000?zip_code=1416 => HTTP 200 'all ok!'
http://localhost:3000 => HTTP 409 'The zip_code parameter is missing'
http://localhost:3000?zip_code=hello => HTTP 409 'The parameter zip_code is wrong'
You can, of course, chain validations to set different criterion of each param:
const { parse } = require('url')
const validate = require('micro-validate')
const numberValidator = p => Number.isInteger(p)
const passportValidator = p => p.length === 8
module.exports = (req, res) => {
const { zip_code, passport_id, message, name, from, to } = parse(req.url, true).query
validate({ zip_code }, numberValidator, 'The parameter {param} must be a number')
validate({ passport_id }, passportValidator, 'The parameter {param} must be 8 characters-length')
validate({ message, name, from, to })
// Use all the parameters!
return 'all ok!'
}
By making some validations you can get several if/switch-repeats, or you may need to program a polymorphic function to not get error at the time you use the parameters. With this package you save the time of doing that letting you just focus on the business logic of the microservice.
npm linknpm link micro-validate. Instead of the default one from npm, node will now use your clone of micro-validate!Thanks to ZEIT Team for giving us micro to make our life easier!
FAQs
Easily validate your microservices url parameters
We found that micro-validate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.