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

check-params

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

check-params

Validates url, body, and query parameters for Express

  • 0.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
Maintainers
1
Weekly downloads
 
Created
Source

check-params

npm npm

Validates url, body, and query parameters for Express

Please ★ this repo if you found it useful ★ ★ ★

Features

  • Check body params
  • Check query params
  • Check url params

Installation

$ npm install --save check-params

Dependencies

Usage

var checkParams = require('check-params');

module.exports = {
  exampleController: function(req, res)  {
    checkParams(req, {
      queryParams: [
        'hello',
        'foo'
      ]
    }).then(function() {
      res.json({
        message: 'Yaaaay, I have everything I need!!!'
      });
    }).catch(function(err) {
      console.warn(err);
      res.status(err.code).json({
        message: err.message
      });
    });
  }
};

Now, if I enter the following url . . .

http://myserver.com/example?hello=world&foo=bar

. . . I get the following response.

{
  "message": "Yaaaay, I have everything I need!!!"
}

However, if I enter the following url, without the query params . . .

http://myserver.com/example

. . . I get the following response.

{
  "message": "You are missing the query params 'hello', and 'foo'."
}

If you do not put in the required parameters, you will get a response asking for them.

More Details

The checkParams function recieves three properties. The last property, options, is optional.

checkParams(
  req, // the request object
  {
    urlParams: [], // an array of required url params
    bodyParams: [], // an array of required body params
    queryParams: [] // an array of required query params
  },
  { // the options property is not required
    distictChar: '\'', // the default character to distinguish missing parameters in the error message 
    oxfordComma: true // whether to use oxford comma's when separating lists
  } 
);

The checkParams function always returns as a promise. It is also good to note, that the err response has a property called code. This contains the suggested response status code.

Support

Submit an issue

Buy Me Coffee

A ridiculous amount of coffee was consumed in the process of building this project.

Add some fuel if you'd like to keep me going!

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT License

Jam Risser © 2017

Credits

Changelog

0.3.0 (2017-06-28)

  • Removed message response

0.1.0 (2016-10-25)

  • Beta release

FAQs

Package last updated on 28 Jun 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