require-params
v1.1.4
Published
require some parameters the easiest way
Downloads
1
Maintainers
Readme
require-params
Fast, minimalist middleware for express making your life easier.
Features:
- Requires important params the easy way
- Choose to force require params
- Or return missing params array with the requst object for you to handle
Installation:
npm i require-params
Usage:
app.use(requireParams('/api/endpoint',['text'],true))
Arguments Explaining:
requireParams(PATH:String,RequiredParmeters:String[],ForceRequireParams?:Boolean)
Full code example:
const express = require('express')
const app = express()
app.use(express.urlencoded({extended: true}));
app.use(express.json())
const requireParams = require('require-params');
app.use(requireParams('/api/endpoint',['text'],true))
app.post('/api/endpoint', (req, res) => {
//code happens here only when required params are provided when force require is enabled
})
This is on GitHub your contributions are very welcomed.