express middleware to set required fields for incoming requests
MIT License
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).
Install the dependency
npm install express-required-fields --save
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 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:
Mocha and Chai are used for testing. To run the tests:
npm test
Email me to [email protected]
If you want to contribute, open a new issue or fork the repository and add a pull request
Read LICENSE.md