I’d like to augment the prototype of the request object in expressjs, but it isn’t clear where this request is defined? I think it is http.ServerRequest, but I can’t find that definition either.
What’s the right way to do the following…
http.ServerRequest.prototype.redirect = function(path) { }
Express itself adds it’s utility methods to
http.IncomingMessage.prototype, using this pattern in 2.*:And this pattern in 3.*:
It’s wise to be careful with monkey patching though, as Vadim Baryshev warns in his answer.