Skip to content

Instantly share code, notes, and snippets.

@raycmorgan
Created September 19, 2009 06:30
Show Gist options
  • Save raycmorgan/189421 to your computer and use it in GitHub Desktop.
Save raycmorgan/189421 to your computer and use it in GitHub Desktop.
node.http.createServer(function (request, response) {
node.fs.cat("path/to/your/file.txt", "raws")
.addCallback(function (contents) {
response.sendHeader(200, {"Content-Type": "text/plain", "Content-Length": contents.length});
response.sendBody(contents);
response.finish();
})
.addErrback(function () {
response.sendHeader(404, {"Content-Type": "text/plain"});
response.sendBody("Not Found");
response.finish();
});
}).listen(8001);
puts("Server running at http://127.0.0.1:8001/");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment