@thedevminertv/body-validator
v1.2.0
Published
Validate Express request bodies easily
Downloads
4
Maintainers
Readme
BodyValidator
BodyValidator allows you to easily check if the request body has certain properties.
Installation
npm install @thedevminertv/body-validator
Usage
const app = require('express')();
const BodyParser = require('body-parser');
const BodyValidator = require('@thedevminertv/body-validator');
// Apply BodyParser to parse JSON
app.use(BodyParser.json());
// Apply the BodyValidator to a route
// This will check that the body should have the "name" property
app.get('/api/test', BodyValidator(['name']), (request, response) => {
res.send(`Hello ${req.body.name}`);
});
app.listen(3000, () => console.log('Server listening on port 3000'));