Internet
Server
Client
Client
Client
GET /index.html HTTP/1.1
Host: www.example.com
HTTP/1.1 200 OK
Date: Mon, 1 Jan 2015 22:38:34 GMT
Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)
Last-Modified: Wed, 31 Dec 2014 23:11:55 GMT
ETag: "3f80f-1b6-3e1cb03b"
Content-Type: text/html; charset=UTF-8
Content-Length: 131
Accept-Ranges: bytes
Connection: close
<html>
<head>
<title>An Example Page</title>
</head>
<body>
Hello World
</body>
</html>
Client Request
Server Response
Status Codes
Blocking Code
function exponentiate(base, index) {
var ans = base;
for (var i=1; i<index; i++) {
ans = ans * base;
}
return ans;
}
console.log(exponentiate(10, 6));
console.log("Hello World");
Non-Blocking Code with callbacks
function exponentiate(base, index, cb) {
var ans = base;
for (var i=1; i<index; i++) {
ans = ans * base;
}
cb(ans);
}
exponentiate(10, 6, function callback(ans) {
console.log(ans);
});
console.log("Hello World");
Non-blocking code allows for highly concurrent applications, allowing support for tens of thousands of concurrent connecions