trim-middleware

1.1.1 • Public • Published

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.

Package Sidebar

Install

npm i trim-middleware

Weekly Downloads

3

Version

1.1.1

License

ISC

Unpacked Size

2.24 kB

Total Files

3

Last publish

Collaborators

  • nodewin