sock := listen(8080)
while True:
request := sock.accept()
file := parse(request)
data := open(file).read()
request.send(data)
var data = fs.readFileSync(
filePath, "binary"
); //blocking
doSomethingGreat(data);
fs.readFile(filePath, "binary",
function(err,data){ //non-blocking
if (err) throw err;
doSomethingGreat(data);
}
);
doMoreAwesomeness();
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
curl http://localhost:8124/
Hello World
curl -I http://localhost:8124/
HTTP/1.1 200 OK
Content-Type: text/plain
Connection: keep-alive
Questions?