2012-02-27 11:09:34 -08:00
|
|
|
# Synopsis
|
|
|
|
|
|
|
|
<!--type=misc-->
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2015-11-13 19:21:49 -08:00
|
|
|
An example of a [web server][] written with Node.js which responds with
|
2015-11-27 18:30:32 -05:00
|
|
|
`'Hello World'`:
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2015-12-14 15:20:25 -08:00
|
|
|
const http = require('http');
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2015-12-14 15:20:25 -08:00
|
|
|
http.createServer( (request, response) => {
|
2010-10-28 23:18:16 +11:00
|
|
|
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-08-13 12:14:34 -04:00
|
|
|
it with the node program
|
2010-10-28 23:18:16 +11:00
|
|
|
|
2015-08-13 12:14:34 -04:00
|
|
|
> node example.js
|
2010-10-28 23:18:16 +11:00
|
|
|
Server running at http://127.0.0.1:8124/
|
|
|
|
|
|
|
|
All of the examples in the documentation can be run similarly.
|
2015-11-13 19:21:49 -08:00
|
|
|
|
|
|
|
[web server]: http.html
|