Permalink
Browse files

Update hello-node article.

  • Loading branch information...
1 parent 68a949d commit 4dc8285b75d1daddc32b495207dca7e87969fc25 @creationix committed Jul 28, 2010
@@ -1,7 +1,7 @@
Title: Hello Node!
Author: Tim Caswell
Date: Mon Mar 22 2010 10:55:41 GMT-0500 (CDT)
-Node: v0.1.91
+Node: v0.1.102
In programming literature it has become the standard to create a hello world program as the first example. This article will go through a few simple hello world type examples with everything from simple terminal output to an http server that uses an external framework for some semantic sugar.
@@ -1,5 +1,2 @@
-// Load the sys module since we want to write to the terminal
-var sys = require('sys');
-
-// Call the puts function on the sys module.
-sys.puts("Hello World");
+// Call the console.log function.
+console.log("Hello World");
@@ -1,17 +1,14 @@
-// Load the sys module for console writing.
-var sys = require('sys');
// Load the http module to create an http server.
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
- response.write("Hello World\n");
- response.close();
+ response.end("Hello World\n");
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);
// Put a friendly message on the terminal
-sys.puts("Server running at http://127.0.0.1:8000/");
+console.log("Server running at http://127.0.0.1:8000/");
@@ -1,5 +1,3 @@
-// Load the sys module for console writing.
-var sys = require('sys');
// Load the net module to create a tcp server.
var net = require('net');
@@ -9,8 +7,7 @@ var server = net.createServer(function (socket) {
// Every time someone connects, tell them hello and then close the connection.
socket.addListener("connect", function () {
sys.puts("Connection from " + socket.remoteAddress);
- socket.write("Hello World\n");
- socket.end();
+ socket.end("Hello World\n");
});
});
@@ -19,4 +16,4 @@ var server = net.createServer(function (socket) {
server.listen(7000, "localhost");
// Put a friendly message on the terminal
-sys.puts("TCP server listening on port 7000 at localhost.");
+console.log("TCP server listening on port 7000 at localhost.");

0 comments on commit 4dc8285

Please sign in to comment.