Uh oh!
There was an error while loading. Please reload this page.
Fix documentation of process.argv[0] - #7449
Conversation
cjihrig
commented
Jun 27, 2016
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
| 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.
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.
I agree with @mscdex. Also, this line should be wrapped at 80 characters.
There was a problem hiding this comment.
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.
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.
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. | ||
| be [`process.execPath()`], second element will be the path to JavaScript file. |
There was a problem hiding this comment.
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.
Done
I think the part about the second element should be a separate sentence:
There was a problem hiding this comment.
It looks like it's still one sentence, just with 'the' removed in two places?
There was a problem hiding this comment.
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.
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.
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 |
These changes are just some grammatical changes like using `an` not `a` and space after period etc.
cjihrig
commented
Jun 29, 2016
LGTM |
1 similar comment
mscdex
commented
Jun 29, 2016
LGTM |
Dmitry-Me
commented
Jul 1, 2016
So sad... we'll have to change our code... |
addaleax
commented
Jul 1, 2016
@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). |
Dmitry-Me
commented
Jul 1, 2016
@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 |
addaleax
commented
Jul 1, 2016
@Dmitry-Me Checking |
Dmitry-Me
commented
Jul 1, 2016
@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.
process.execPath is not a function, so I’d drop the parentheses?
addaleax
commented
Jul 1, 2016
LGTM with a nit. |
jasnell
commented
Jul 1, 2016
LGTM |
tarungarg546
commented
Jul 2, 2016
What's next? |
addaleax
commented
Jul 4, 2016
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 <cjihrig@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
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 <cjihrig@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
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 <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
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 <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
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]