-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Fix documentation of process.argv[0] #7449
Conversation
Could you format the commit message according to https://github.com/nodejs/node/blob/master/CONTRIBUTING.md#step-3-commit. |
The current documentation states that if run something like node app.js then in our process.argv array first elements is node, but actually its process.execPath not node as documentation currently suggests This commit fixes this documentation bug. Fixes : nodejs#7434 PR-URL: nodejs#7449
@@ -452,7 +452,7 @@ added: v0.1.27 | |||
|
|||
The `process.argv` property returns a array containing the command line | |||
arguments passed when the Node.js process was launched. The first element will | |||
be 'node', the second element will be the name of the JavaScript file. The | |||
be [`process.execPath()`], the second element will be the name of the JavaScript file. The |
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.
While we're in here, we may as well change "name of the JavaScript file" to something like "path to the JavaScript file."
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.
Seems fair enough?
What say @cjihrig
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.
I agree with @mscdex. Also, this line should be wrapped at 80 characters.
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.
Hm. Is it a bug then that running a file named test.js
using node test
will lead to process.argv[1] === '/path/to/test'
, not /path/to/test.js
?
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.
hmm.. that's an interesting question... but I think that's ok. While there is the potential for conflicts because of the missing .js
, it's not likely to have a serious impact. I guess that someone could come along and create a separate file named test
after the app was started that would lead to issues but that seems like a relatively safe edge case.
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.
Done @cjihrig
With this commit everyline of process documentation is wrapped in 80 characters and there are some changes for documention of process.arv[0] and process.argv[1]
@@ -452,8 +452,8 @@ added: v0.1.27 | |||
|
|||
The `process.argv` property returns a array containing the command line | |||
arguments passed when the Node.js process was launched. The first element will | |||
be 'node', the second element will be the name of the JavaScript file. The | |||
remaining elements will be any additional command line arguments. | |||
be [`process.execPath()`], second element will be the path to JavaScript file. |
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.
I think the part about the second element should be a separate sentence:
The second element will be the path to the JavaScript file being executed.
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.
Done
I think the part about the second element should be a separate sentence:
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.
It looks like it's still one sentence, just with 'the' removed in two places?
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.
Oh sorry forgot to push changes.
With this commit everyline of process documentation is wrapped in 80 characters and there are some changes for documention of process.arv[0] and process.argv[1]
be 'node', the second element will be the name of the JavaScript file. The | ||
remaining elements will be any additional command line arguments. | ||
arguments passed when the Node.js process was launched. | ||
The first element will be [`process.execPath()`], |
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.
No need to split all of these across lines. Just wrap them at 80 characters. Also, the sentence should end with a period, not a comma.
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.
done.
With this commit everyline of process documentation is wrapped in 80 characters and there are some changes for documention of process.arv[0] and process.argv[1]
arguments passed when the Node.js process was launched. The first element will | ||
be 'node', the second element will be the name of the JavaScript file. The | ||
remaining elements will be any additional command line arguments. | ||
The `process.argv` property returns a array containing the command line |
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.
a -> an
These changes are just some grammatical changes like using `an` not `a` and space after period etc.
LGTM |
1 similar comment
LGTM |
So sad... we'll have to change our code... |
@Dmitry-Me It might help if you could describe your use case (but probably better in the original issue, as long as it doesn’t concern this documentation change itself). |
@addaleax We host a piece of sample code for our users. Because it's JavaScript some of them try to run it inside web browser, which of course doesn't work. So we need a check that effectively "code is being run under NodeJS". Earlier we could just check that |
@Dmitry-Me Checking |
@addaleax Would just checking for presence of |
@Dmitry-Me For the scenario you described, i.e. users trying to run the file in a browser with nothing else going on, yes. Google will gladly lead you to a thousand different ways to check whether code is being run under EDIT: Again, if there are more follow-up questions, these probably are better asked at the original issue (nodejs/help might be a better place, too). |
remaining elements will be any additional command line arguments. | ||
The `process.argv` property returns an array containing the command line | ||
arguments passed when the Node.js process was launched. The first element will | ||
be [`process.execPath()`]. The second element will be the path to the |
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.
process.execPath
is not a function, so I’d drop the parentheses?
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.
Done 👍
LGTM with a nit. |
LGTM |
What's next? |
Landed in 475dc43, thank for the contribution! |
The current documentation states that if run something like `node app.js` then in our process.argv array first elements is `node`, but actually it's `process.execPath` not `node` as documentation currently suggests. Fixes: #7434 PR-URL: #7449 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
The current documentation states that if run something like `node app.js` then in our process.argv array first elements is `node`, but actually it's `process.execPath` not `node` as documentation currently suggests. Fixes: #7434 PR-URL: #7449 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
For historical and other reasons, node overwrites `argv[0]` on startup. See - 2c6f79c, - nodejs#7434 - nodejs#7449 - nodejs#7696 For cases where it may be useful, save the original value of `argv[0]` in `process.argv0`
For historical and other reasons, node overwrites `argv[0]` on startup. See - 2c6f79c, - #7434 - #7449 - #7696 For cases where it may be useful, save the original value of `argv[0]` in `process.argv0` PR-URL: #7696 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
For historical and other reasons, node overwrites `argv[0]` on startup. See - 2c6f79c, - #7434 - #7449 - #7696 For cases where it may be useful, save the original value of `argv[0]` in `process.argv0` PR-URL: #7696 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
Checklist
Affected core subsystem(s)
doc
Description of change
This PR is in reference for this issue.
Modified docs to reflect original value of
process.argv[0]