-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc : being more explicit in the synopsis #17977
Changes from 1 commit
ab55bf3
2d75d3d
9e91b41
5427e5a
f42d3c2
bf4e20f
47cf571
54b63eb
3afa466
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,43 @@ Please see the [Command Line Options][] document for information about | |
different options and ways to run scripts with Node.js. | ||
|
||
## Example | ||
|
||
An example of a [web server][] written with Node.js which responds with | ||
`'Hello World'`: | ||
`'Hello World!'`: | ||
|
||
Firstly, Make sure you have downloaded Node.js from [Node.js Official website](http://nodejs.org/#download). | ||
Then, Follow this [installation guide](https://nodejs.org/en/download/package-manager/). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe change:
to
If people are just getting started with Node they probably don't need to know about package managers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow -> follow? |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docs are usually single-spaced. I'm not sure that double-spacing like this will render the same as other docs. Probably best to single-space it. (Blank lines between paragraphs are 👍 though!) |
||
|
||
Now, Create an empty project folder called `projects`, navigate into it: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create -> create? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you tweak this to make it clear that Maybe:
(
https://doc.rust-lang.org/book/second-edition/ch01-02-hello-world.html#creating-a-project-directory |
||
|
||
Linux and Mac: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be UNIX rather than Linux and Mac ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually go with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We seem to be using If we use Linux and MAC, it leaves an impression of either:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gireeshpunathil I'm convinced. Let's go with |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you include something like this:
(taken from https://doc.rust-lang.org/book/second-edition/ch01-01-installation.html#installation, feel free to reword it). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gibfahn Note my previous comments about personal pronouns. I wonder if this should really be a guide so that we don't have to worry about that sort of thing. Link to it from the docs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you include something like this:
(taken from https://doc.rust-lang.org/book/second-edition/ch01-01-installation.html#installation, feel free to reword it). |
||
```txt | ||
$ mkdir ~/projects | ||
$ cd ~/projects | ||
``` | ||
Windows CMD: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is always good to have a blank line before and after code / markdown blocks etc. |
||
```txt | ||
> mkdir %USERPROFILE%\projects | ||
> cd %USERPROFILE%\projects | ||
``` | ||
|
||
Windows PowerShell: | ||
|
||
```txt | ||
> mkdir $env:USERPROFILE\projects | ||
> cd $env:USERPROFILE\projects | ||
``` | ||
|
||
Next, create a new source file in the `projects` folder and call it `hello_world.js`. | ||
|
||
If you’re using more than one word in your filename, use an underscore(`_`) to separate them for simplicity and avoid using the space character in file names. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe "use an underscore ( |
||
|
||
For example, you’d use `hello_world.js` rather than `hello world.js`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually do not use personal pronouns in the docs, but this guide is a less formal one, so I am not sure if this is OK. Let's see what others think. |
||
Node.js files always end with the `.js` extension. | ||
|
||
open `hello_world.js` in your favorite text editor and paste in the following content. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. open -> Open? |
||
|
||
|
||
```js | ||
const http = require('http'); | ||
|
@@ -22,21 +56,25 @@ const port = 3000; | |
const server = http.createServer((req, res) => { | ||
res.statusCode = 200; | ||
res.setHeader('Content-Type', 'text/plain'); | ||
res.end('Hello World\n'); | ||
res.end('Hello World!\n'); | ||
}); | ||
|
||
server.listen(port, hostname, () => { | ||
console.log(`Server running at http://${hostname}:${port}/`); | ||
}); | ||
``` | ||
|
||
To run the server, put the code into a file called `example.js` and execute | ||
it with Node.js: | ||
Save the file, and go back to your terminal window enter the following command: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Save the file, go back to your terminal window and enter? |
||
|
||
```txt | ||
$ node example.js | ||
Server running at http://127.0.0.1:3000/ | ||
$ node hello_world.js | ||
``` | ||
Your should see an output like this in your terminal to indicate Node.js server is running: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your -> you? (If pronouns are considered appropriate). |
||
```javascript | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe remove the |
||
Server running at http://127.0.0.1:3000/ | ||
```` | ||
Now, Open your favorite browser and visit `http://127.0.0.1:3000`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Open ->open? |
||
|
||
You should see the string `Hello, world!`. | ||
|
||
Many of the examples in the documentation can be run similarly. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make -> make?