Skip to content

Instantly share code, notes, and snippets.

@robwormald
Created January 21, 2014 05:19
Show Gist options
  • Save robwormald/8534814 to your computer and use it in GitHub Desktop.
Save robwormald/8534814 to your computer and use it in GitHub Desktop.
var http = require('http');
var querystring = require('querystring')
var url = require('url');
//pointless async function
function doAsyncMath(param1,param2,callback){
var sum = param1 + param2
//first param in callbacks is usually the error
callback(null,sum)
}
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
//same basic thing, but here just using an anonymnous func as the callback
doAsyncMath(1,2,function(err,sum){
//err and sum here come from the callback on line 15
if(err) return response.end(err)
response.writeHead(200, {"Content-Type": "text/plain"});
response.end(sum.toString());
})
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment