Skip to content

Instantly share code, notes, and snippets.

@DominicFinn
Created July 28, 2013 12:50
Show Gist options
  • Select an option

  • Save DominicFinn/6098468 to your computer and use it in GitHub Desktop.

Select an option

Save DominicFinn/6098468 to your computer and use it in GitHub Desktop.
Anonymous functions vs Named Functions for Node.js
var start = function(route) {
// sets up the server
http.createServer(function(request, response) {
var pathName = url.parse(request.url).pathname;
console.log("Request for " + pathName + " Recieved");
route(pathName);
response.writeHead(200, { "content-type": "text/plain" });
response.write("Hello World!");
response.end();
}).listen(8888);
console.log("Server has started");
}
function start(route) {
function process(request, response) {
var pathName = url.parse(request.url).pathname;
console.log("Request for " + pathName + " Recieved");
route(pathname);
response.writeHead(200, { "content-type": "text/plain" });
response.write("Hello World!");
response.end();
}
// sets up the server
http.createServer(process).listen(8888);
console.log("Server has started");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment