Skip to content

Instantly share code, notes, and snippets.

@cdario
Last active December 20, 2015 08:49
Show Gist options
  • Save cdario/6102877 to your computer and use it in GitHub Desktop.
Save cdario/6102877 to your computer and use it in GitHub Desktop.
Node.js: Reads a file in the server and writes its contents to the response. Nested non-blocking calls
var http = require('http');
var fs = require('fs');
http.createServer(function(request, response) {
response.writeHead(200); // 1.
var callback = function(err, contents){
response.write(contents); // 3.
response.end(); // 4.
}
fs.readFile('index.html',callback) // 2.
}).listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment