Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 401325f

Browse filesBrowse files
Fishrock123Myles Borins
authored andcommitted
doc: better example & synopsis
PR-URL: #6167 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Robert Jefe Lindstädt <robert.lindstaedt@gmail.com>
1 parent c654184 commit 401325f
Copy full SHA for 401325f

File tree

Expand file treeCollapse file tree

2 files changed

+23
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-9
lines changed
Open diff view settings
Collapse file

‎doc/api/_toc.markdown‎

Copy file name to clipboardExpand all lines: doc/api/_toc.markdown
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
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)
Collapse file

‎doc/api/synopsis.markdown‎

Copy file name to clipboard
+22-8Lines changed: 22 additions & 8 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.