Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

req-check

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

req-check

Req body and query parameter validation.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

node-req-check

Request query and body parameter checking.

Usage

The various check methods create a middleware that can be dropped onto your route. They will check either the query or body parameter of the request depending on the value of req.method. GET and DELETE requests will use the req.query, all other methods will use req.body.

const check = require('req-check');

app.get('/search', check.string({name: 'query', required: true}), searchEndpoint);

app.post(
  '/user/login',
  check.email({name: 'email', required: true}),
  check.string({name: 'password', required: true, min: 3}),
  userLoginEndpoint
);

Available Checks

check.string

Checks that a given parameter exists with length constraints. No validation of the value of the parameter is made other than potentially checking the length.

Options:

  • name: The name of the parameter to check.
  • required: Boolean indicating if the parameter is required.
  • min: Integer minimum parameter length.
  • max: Integer maximum parameter length.

check.email

Checks that the given parameter exists and could be a valid email. The email validation is minimal since email validation is really complex and hard to get perfect.

Options:

  • name: The name of the parameter to check.
  • required: Boolean indicating if the parameter is required.

check.array

Checks that the given parameter exists and is an array. If the parameter is a string it will be split first using the delim option.

Options:

  • name: The name of the parameter to check.
  • required: Boolean indicating if the parameter is required.
  • min: Integer minimum parameter length.
  • max: Integer maximum parameter length.
  • delim: Delimiter to pass to str.split. Default is /,\s*/g.

check.int

Checks that the given parameter exists and is an integer. If the parameter is a string it will be parsed first using the radix option.

Options:

  • name: The name of the parameter to check.
  • required: Boolean indicating if the parameter is required.
  • min: Integer minimum parameter value.
  • max: Integer maximum parameter value.
  • radix: Radix to pass to parseInt. Default is 10.

Keywords

FAQs

Package last updated on 17 Oct 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc