Synopsis

An example of a web server written with Node which responds with ‘Hello
World’:

  1. var http = require('http');
  2. http.createServer(function (request, response) {
  3. response.writeHead(200, {'Content-Type': 'text/plain'});
  4. response.end('Hello World\n');
  5. }).listen(8124);
  6. console.log('Server running at http://127.0.0.1:8124/');

To run the server, put the code into a file called example.js and execute
it with the node program

  1. > node example.js
  2. Server running at http://127.0.0.1:8124/

All of the examples in the documentation can be run similarly.