Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway to remove anything from the request object you get in express middleware?

Most express middleware look like this:

var foo = function( req, res, next ) {

}

Is there anyway to REMOVE properties from the req object such that it will reflected in the next handler in the stack?

like image 341
Josh Elias Avatar asked Sep 17 '25 03:09

Josh Elias


1 Answers

Just delete it.

For example:

function logout (req, res, next){
    delete req.session['user'];
    res.redirect(302,'/');
};

Obviously if you are deleting things subsequent middleware expects to be present you may have issues.

You can read the doc on delete here.

like image 92
barry-johnson Avatar answered Sep 19 '25 23:09

barry-johnson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!