Last active
December 20, 2015 08:49
-
-
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
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 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