1.1.1 • Published 4 years ago

trim-middleware v1.1.1

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

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: Request

Don't forget the withespaces

And in terminal:

Response

It's useful for public app for password, pseudo and other.