Skip to content

Godwin-sys-php/trim-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published