2012-02-27 20:09:34 +01:00
|
|
|
# Synopsis
|
|
|
|
|
|
|
|
<!--type=misc-->
|
2010-10-28 14:18:16 +02:00
|
|
|
|
2015-02-07 11:25:13 +01:00
|
|
|
An example of a [web server](http.html) written with io.js which responds with
|
|
|
|
'Hello World':
|
2010-10-28 14:18:16 +02:00
|
|
|
|
|
|
|
var http = require('http');
|
|
|
|
|
|
|
|
http.createServer(function (request, response) {
|
|
|
|
response.writeHead(200, {'Content-Type': 'text/plain'});
|
|
|
|
response.end('Hello World\n');
|
|
|
|
}).listen(8124);
|
|
|
|
|
|
|
|
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
|
2015-02-07 11:25:13 +01:00
|
|
|
it with the iojs program
|
2010-10-28 14:18:16 +02:00
|
|
|
|
2015-02-07 11:25:13 +01:00
|
|
|
> iojs example.js
|
2010-10-28 14:18:16 +02:00
|
|
|
Server running at http://127.0.0.1:8124/
|
|
|
|
|
|
|
|
All of the examples in the documentation can be run similarly.
|