A Simple Middleware that automatically trim the body of requests
Run this command:
npm install --save trim-middleware
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());
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.