Last active
December 15, 2015 20:57
-
-
Save quadrophobiac/1e27e707c78036fdd7d0 to your computer and use it in GitHub Desktop.
node module patterns quandry for server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Server = require('./../AnonymousPrototypeModule.js'); | |
console.log("this server is a "+typeof Server); // returns this server is a function | |
console.log(Object.getOwnPropertyNames(Server)); // [ 'length', 'name', 'arguments', 'caller', 'prototype' ] | |
var server = new Server(); | |
console.log("this invoked server is a "+typeof server); // returns this invoked server is a object | |
console.log(Object.getOwnPropertyNames(server)); // returns [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Server = function(){}; | |
Server.prototype.commence = function(){ | |
console.log("starting server"); | |
Server.server = http.createServer(function(req,res){ | |
res.writeHead(200,{'Content-Type': 'text/plain'}); | |
res.end('Hello, world!\n'); | |
}); | |
} | |
Server.prototype.listen = function(){ | |
Server.server.listen.apply(Server.server, arguments); | |
} | |
Server.prototype.close = function(callback){ | |
Server.server.close(callback); | |
} | |
module.exports = Server; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Server(){} | |
Server.commence = function(){ | |
console.log("starting server"); | |
Server.server = http.createServer(function(req,res){ | |
res.writeHead(200,{'Content-Type': 'text/plain'}); | |
res.end('Hello, world!\n'); | |
}); | |
} | |
Server.listen = function(){ | |
Server.server.listen.apply(Server.server, arguments); | |
} | |
Server.close = function(callback){ | |
Server.server.close(callback); | |
} | |
module.exports = Server; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Server = require('./../NamedFunctionExport.js'); | |
CentrifugeServer.commence(); | |
console.log("this server is a "+typeof CentrifugeServer); // returns this server is a function | |
console.log(Object.getOwnPropertyNames(CentrifugeServer)); // returns [ 'length','name','arguments','caller','prototype','commence','listen','close','server' ] | |
CentrifugeServer.listen(8000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment