trim-middleware
v1.1.1
Published
Middleware that automatically trim the body of requests
Downloads
15
Readme
trim-middleware
A Simple Middleware that automatically trim the body of requests
Installation
Run this command:
npm install --save trim-middleware
Prerequisite
You must have express and body-parser in your app like this:
const express = require("express");
const bodyParser = require('body-parser');
const app = express();
const trimMiddleware= require('trim-middleware')
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(trimMiddleware());
Test it
Run this code after install express, body-parser and trim-middleware:
const express = require("express");
const bodyParser = require('body-parser');
const app = express();
const trimMiddleware= require('trim-middleware')
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(trimMiddleware());
app.post('/test', (req, res) => {
console.log(req.body)
// or
res.json(req.body)
});
app.listen(3000);
And with postman make the request with this body:
Don't forget the withespaces
And in terminal:
It's useful for public app for password, pseudo and other.