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

StackOverflow https://stackoverflow.com/questions/23275344

  •  09-07-2023
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top