Created
July 28, 2013 12:50
-
-
Save DominicFinn/6098468 to your computer and use it in GitHub Desktop.
Anonymous functions vs Named Functions for Node.js
This file contains hidden or 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 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