New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

express-required-fields

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-required-fields

express middleware to set required fields for incoming requests

latest
Source
npmnpm
Version
1.1.2
Version published
Weekly downloads
27
-48.08%
Maintainers
1
Weekly downloads
 
Created
Source

express-required-fields

Greenkeeper badge npm version Build Status

Synopsis

Express middleware to set required fields for incoming requests. Responds with error message if fields are missing in the request body (headers and/or query as an option).

Installation

Install the dependency

npm install express-required-fields --save

Code Example

Sample usage:

var express = require('express');
var app = express();
var required = require('express-required-fields')

app.post('/register', required(['email', 'password']), (req, res)=>{
  //this code will run if required fields are included in the request body
  })

Options

Options can be used to customize the response. They can be passed as a second parameter

var express = require('express');
var app = express();
var required = require('express-required-fields')

app.post('/register', required(['email', 'password'],{ error_status:432, message:'A custom message' }), (req, res)=>{
  //this code will run if required fields are included in the request body
  })

Default options values are:

  • error_status: 400
  • message: 'Bad Request'
  • show_required: true
  • show_received: true
  • accept_headers: false
  • accept_query: false

Tests

Mocha and Chai are used for testing. To run the tests:

npm test

Connect with the author

Email me to flakolefluk@gmail.com

Contributors

If you want to contribute, open a new issue or fork the repository and add a pull request

License

Read LICENSE.md

Keywords

express

FAQs

Package last updated on 29 Oct 2018

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