Get status code in express middleware
You can override res.end
event that is being called whenever response ends. You can get statusCode
of response whenever response ends.
Hope it helps you
var end = res.end;
res.end = function(chunk, encoding) {
if(res.statusCode == 200){
// cache file only if response status code is 200
cacheFile(cacheFilePath, body);
}
res.end = end;
res.end(chunk, encoding);
};
you can use res.statusCode to the get the status.