DEV Community

Cover image for Three useful Express middleware

Three useful Express middleware

Zell Liew πŸ€— on September 18, 2019

As I created applications with Express and Node, I learned about three useful middlewares: Morgan Camelcase Remove empty properties Of these th...
Collapse
 
ajinspiro profile image
Arun Kumar

Hi, I don't understand why you create the high order function like this

const removeEmptyProperties = () => {
return function(req, res, next) {
req.body = omitEmpty(req.body);
req.params = omitEmpty(req.params);
req.query = omitEmpty(req.query);
next();
};
};

and use it like this

app.use(removeEmptyProperties());

Isn't creating the function like this

const removeEmptyProperties = (req, res, next) => {
req.body = omitEmpty(req.body);
req.params = omitEmpty(req.params);
req.query = omitEmpty(req.query);
next();
};

and using it like this

app.use(removeEmptyProperties);

enough?

Collapse
 
scriptmunkee profile image
Ken Simeon • Edited

Thanks for this write up. As a dev that's new to Node & Express, having a package like Morgan that provides me some details about the requests hitting my routes is fantastic. Plus it will reduces the amount of console.log() statements I'd have to write. πŸ‘πŸ½

Collapse
 
eriknguyen profile image
Erik Nguyen

Hi, I'm wondering how is the impact of these to your app performance?

Collapse
 
bcdbuddy profile image
Babacar Cisse DIA

this is so much useful! thank you! πŸ‘πŸ‘

Collapse
 
allanjeremy profile image
Allan N Jeremy

Perfect! Feels like I just discovered a hidden gem.

Downloading these as soon as I get back to a computer. Thanks for sharing Zell!

Collapse
 
prashanthr profile image
Prashanth R.

Super useful middleware(s) πŸ’―