Skip to content

Commit d9a045f

Browse files
committed
update chapter 2 examples to match book
1 parent 8a5801f commit d9a045f

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

02-01.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
var http = require("http");
22

33
http.createServer(function(req, res) {
4-
var page = ["<!doctype html>",
5-
"<html><head><title>Hello world</title></head>",
6-
"<body><h1>Hello, world!</h1></body></html>"]
7-
html = page.join("");
4+
var html = "<!doctype html>" +
5+
"<html><head><title>Hello world</title></head>" +
6+
"<body><h1>Hello, world!</h1></body></html>";
7+
8+
res.writeHead(200, {
9+
"Content-Type": "text/html",
10+
"Content-Length": html.length
11+
});
812

913
res.end(html);
1014
}).listen(8000);

02-02.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@ http.createServer(function(req, res) {
2020
});
2121
}
2222

23-
}).listen(8000, "127.0.0.1");
23+
}).listen(8000);
2424

2525
function getFile(localPath, res) {
2626
fs.readFile(localPath, function(err, contents) {
2727
if (!err) {
28-
res.writeHead(200, {
29-
"Content-Type": "text/html",
30-
"Content-Length": contents.length
31-
});
3228
res.end(contents);
3329
} else {
3430
res.writeHead(500);

02-03.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ http.createServer(function(req, res) {
2828
});
2929
}
3030

31-
}).listen(8000, "127.0.0.1");
31+
}).listen(8000);
3232

3333
function getFile(localPath, mimeType, res) {
3434
fs.readFile(localPath, function(err, contents) {

02-04.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var http = require("http"),
2-
connect = require("connect");
1+
var connect = require("connect");
32

43
connect(connect.static(__dirname + "/public")).listen(8000);

0 commit comments

Comments
 (0)