Chapter 2. JavaScript and asynchronous code

If you go to the actual NodeJS.org home page and not just the download page, you might not need to scroll to find a code sample that looks pretty much like this:

var http = require('http');http.createServer(function (req, res) {  res.writeHead(200, {'Content-Type': 'text/plain'});  res.end('Hello World\n');}).listen(1234, '127.0.0.1');console.log('Server running at http://127.0.0.1:1234/');

This sample is followed by a section that says the following:

"To run the server, put the code into a file example.js and execute it with the node programfrom the command line:"% node example.js

That produces output in the console that says this:

Get Node.js for .NET Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.