summaryrefslogtreecommitdiff
path: root/doc/api/synopsis.md
blob: 7dd3b8fe99d7fda71ddc4a54eddc8967593158fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Synopsis

<!--type=misc-->

An example of a [web server][] written with Node.js which responds with
`'Hello World'`:

```js
const http = require('http');

http.createServer( (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
it with the node program

```
$ node example.js
Server running at http://127.0.0.1:8124/
```

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

[web server]: http.html