Skip to content

Commit 401325f

Browse files
Fishrock123Myles Borins
authored and
Myles Borins
committed
doc: better example & synopsis
PR-URL: #6167 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Robert Jefe Lindstädt <[email protected]>
1 parent c654184 commit 401325f

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

doc/api/_toc.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@// NB(chrisdickinson): if you move this file, be sure to update tools/doc/html.js to
22
@// point at the new location.
33
* [About these Docs](documentation.html)
4-
* [Synopsis](synopsis.html)
4+
* [Usage & Example](synopsis.html)
55
* [Assertion Testing](assert.html)
66
* [Buffer](buffer.html)
77
* [C/C++ Addons](addons.html)

doc/api/synopsis.markdown

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
1-
# Synopsis
1+
# Usage
22

33
<!--type=misc-->
44

5+
`node [options] [v8 options] [script.js | -e "script"] [arguments]`
6+
7+
Please see the [Command Line Options][] document for information about
8+
different options and ways to run scripts with Node.
9+
10+
## Example
11+
512
An example of a [web server][] written with Node.js which responds with
613
`'Hello World'`:
714

815
```js
916
const http = require('http');
1017

11-
http.createServer( (request, response) => {
12-
response.writeHead(200, {'Content-Type': 'text/plain'});
13-
response.end('Hello World\n');
14-
}).listen(8124);
18+
const hostname = '127.0.0.1';
19+
const port = 3000;
20+
21+
const server = http.createServer((req, res) => {
22+
res.statusCode = 200;
23+
res.setHeader('Content-Type', 'text/plain');
24+
res.end('Hello World\n');
25+
});
1526

16-
console.log('Server running at http://127.0.0.1:8124/');
27+
server.listen(port, hostname, () => {
28+
console.log(`Server running at http://${hostname}:${port}/`);
29+
});
1730
```
1831

1932
To run the server, put the code into a file called `example.js` and execute
20-
it with the node program
33+
it with Node.js:
2134

2235
```
2336
$ node example.js
24-
Server running at http://127.0.0.1:8124/
37+
Server running at http://127.0.0.1:3000/
2538
```
2639

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

42+
[Command Line Options]: cli.html#cli_command_line_options
2943
[web server]: http.html

0 commit comments

Comments
 (0)