@@ -14,8 +14,8 @@ An example of a [web server][] written with Node.js which responds with
14
14
15
15
Commands displayed in this document are shown starting with ` $ ` or ` > `
16
16
to replicate how they would appear in a user's terminal.
17
- Do not include the ` $ ` and ` > ` character.
18
- They are there to indicate the start of each command.
17
+ Do not include the ` $ ` and ` > ` character they are there to
18
+ indicate the start of each command.
19
19
20
20
There are many tutorials and examples that follow this
21
21
convention: ` $ ` or ` > ` for commands run as a regular user, and ` # `
@@ -24,22 +24,22 @@ for commands that should be executed as an administrator.
24
24
Lines that don’t start with ` $ ` or ` > ` character are typically showing
25
25
the output of the previous command.
26
26
27
- Firstly, make sure to have downloaded Node.js from [ Node.js Official website] ( http://nodejs.org/#download ) .
28
-
29
- To install Node using a package manager, see [ this guide] ( https://nodejs.org/en/download/package-manager/ ) .
30
-
27
+ Firstly, make sure to have downloaded and installed Node.js.
28
+ See [ this guide] [ ] for further install information.
31
29
32
30
Now, create an empty project folder called ` projects ` , navigate into it:
33
31
Project folder can be named base on user's current project title but
34
32
this example will use ` projects ` as the project folder.
35
33
36
- UNIX :
34
+ Linux and Mac :
37
35
38
36
``` console
39
37
$ mkdir ~ /projects
40
38
$ cd ~ /projects
41
39
```
40
+
42
41
Windows CMD:
42
+
43
43
``` console
44
44
> mkdir %USERPROFILE%\p rojects
45
45
> cd %USERPROFILE%\p rojects
@@ -55,17 +55,12 @@ Windows PowerShell:
55
55
Next, create a new source file in the ` projects ` folder
56
56
and call it ` hello-world.js ` .
57
57
58
- If filename has more than one word, use a hyphen(` - ` ) or
59
- an underscore(` _ ` ) to separate them for simplicity and avoid using
60
- the space character in file names.
61
-
62
- For example, use ` hello-world.js ` rather than ` hello world.js ` .
63
- Node.js files always end with the ` .js ` extension.
58
+ In Node.js it is considered good style to use hyphens (` - ` ) or underscores (` _ ` ) to separate
59
+ multiple words in filenames.
64
60
65
61
Open ` hello-world.js ` in any preferred text editor and paste in the following
66
62
content.
67
63
68
-
69
64
``` js
70
65
const http = require (' http' );
71
66
@@ -82,16 +77,20 @@ server.listen(port, hostname, () => {
82
77
console .log (` Server running at http://${ hostname} :${ port} /` );
83
78
});
84
79
```
80
+
85
81
Save the file, go back to the terminal window enter the following command:
86
82
87
83
``` console
88
84
$ node hello-world.js
89
85
```
90
- an output like this should appear in the terminal to indicate Node.js
86
+
87
+ An output like this should appear in the terminal to indicate Node.js
91
88
server is running:
89
+
92
90
``` console
93
91
Server running at http://127.0.0.1:3000/
94
92
````
93
+
95
94
Now, open any preferred web browser and visit `http://127.0.0.1:3000`.
96
95
97
96
If the browser displays the string `Hello, world!`, that indicates
@@ -101,3 +100,5 @@ Many of the examples in the documentation can be run similarly.
101
100
102
101
[Command Line Options]: cli.html#cli_command_line_options
103
102
[web server]: http.html
103
+ [this guide]: https://nodejs.org/en/download/package-manager/
104
+ [Node.js Official website]: http://nodejs.org/#download
0 commit comments