Skip to content

Commit 50bdf0e

Browse files
timotewgibfahn
authored andcommitted
doc: be more explicit in the sypnosis
Assuming less knowledge on the part of the reader, making it easier to get start using Node.js. PR-URL: #17977 Fixes: #17970, Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent 1faae90 commit 50bdf0e

File tree

1 file changed

+68
-8
lines changed

1 file changed

+68
-8
lines changed

doc/api/synopsis.md

+68-8
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,58 @@ Please see the [Command Line Options][] document for information about
99
different options and ways to run scripts with Node.js.
1010

1111
## Example
12-
1312
An example of a [web server][] written with Node.js which responds with
14-
`'Hello World'`:
13+
`'Hello World!'`:
14+
15+
Commands displayed in this document are shown starting with `$` or `>`
16+
to replicate how they would appear in a user's terminal.
17+
Do not include the `$` and `>` character they are there to
18+
indicate the start of each command.
19+
20+
There are many tutorials and examples that follow this
21+
convention: `$` or `>` for commands run as a regular user, and `#`
22+
for commands that should be executed as an administrator.
23+
24+
Lines that don’t start with `$` or `>` character are typically showing
25+
the output of the previous command.
26+
27+
Firstly, make sure to have downloaded and installed Node.js.
28+
See [this guide][] for further install information.
29+
30+
Now, create an empty project folder called `projects`, navigate into it:
31+
Project folder can be named base on user's current project title but
32+
this example will use `projects` as the project folder.
33+
34+
Linux and Mac:
35+
36+
```console
37+
$ mkdir ~/projects
38+
$ cd ~/projects
39+
```
40+
41+
Windows CMD:
42+
43+
```console
44+
> mkdir %USERPROFILE%\projects
45+
> cd %USERPROFILE%\projects
46+
```
47+
48+
Windows PowerShell:
49+
50+
```console
51+
> mkdir $env:USERPROFILE\projects
52+
> cd $env:USERPROFILE\projects
53+
```
54+
55+
Next, create a new source file in the `projects`
56+
folder and call it `hello-world.js`.
57+
58+
In Node.js it is considered good style to use
59+
hyphens (`-`) or underscores (`_`) to separate
60+
multiple words in filenames.
61+
62+
Open `hello-world.js` in any preferred text editor and
63+
paste in the following content.
1564

1665
```js
1766
const http = require('http');
@@ -22,23 +71,34 @@ const port = 3000;
2271
const server = http.createServer((req, res) => {
2372
res.statusCode = 200;
2473
res.setHeader('Content-Type', 'text/plain');
25-
res.end('Hello World\n');
74+
res.end('Hello World!\n');
2675
});
2776

2877
server.listen(port, hostname, () => {
2978
console.log(`Server running at http://${hostname}:${port}/`);
3079
});
3180
```
3281

33-
To run the server, put the code into a file called `example.js` and execute
34-
it with Node.js:
82+
Save the file, go back to the terminal window enter the following command:
3583

36-
```txt
37-
$ node example.js
38-
Server running at http://127.0.0.1:3000/
84+
```console
85+
$ node hello-world.js
3986
```
4087

88+
An output like this should appear in the terminal to indicate Node.js
89+
server is running:
90+
91+
```console
92+
Server running at http://127.0.0.1:3000/
93+
````
94+
95+
Now, open any preferred web browser and visit `http://127.0.0.1:3000`.
96+
97+
If the browser displays the string `Hello, world!`, that indicates
98+
the server is working.
99+
41100
Many of the examples in the documentation can be run similarly.
42101

43102
[Command Line Options]: cli.html#cli_command_line_options
44103
[web server]: http.html
104+
[this guide]: https://nodejs.org/en/download/package-manager/

0 commit comments

Comments
 (0)