I want to derive the Node.js http(s) server, as I need to add some behavior.
E.g., I want to have an http server that also has a foobar function. So I want to be able to do something like this:
var server = http.createServer(function (req, res) { ... }).listen(3000);
server.foobar();
Of course I somehow need to derive from the http module, but how could I do this? Apparently there is no Http constructor I could override ...
Any ideas or hints?
I haven't tested, but giving in it a though I would say you would only have to:
var http = require('http');
http.Server.prototype.foobar = function () {};
As you can see here the createServer function is nothing but a factory instantiating a new Server object that was exposed two lines before.