| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Could you format the commit message according to https://github.com/nodejs/node/blob/master/CONTRIBUTING.md#step-3-commit. |
Sorry, something went wrong.
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."
Sorry, something went wrong.
There was a problem hiding this comment.
Seems fair enough?
What say @cjihrig
Sorry, something went wrong.
There was a problem hiding this comment.
I agree with @mscdex. Also, this line should be wrapped at 80 characters.
Sorry, something went wrong.
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?
Sorry, something went wrong.
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.
Sorry, something went wrong.
There was a problem hiding this comment.
Done @cjihrig
Sorry, something went wrong.
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.
Sorry, something went wrong.
There was a problem hiding this comment.
Done
I think the part about the second element should be a separate sentence:
Sorry, something went wrong.
There was a problem hiding this comment.
It looks like it's still one sentence, just with 'the' removed in two places?
Sorry, something went wrong.
There was a problem hiding this comment.
Oh sorry forgot to push changes.
Sorry, something went wrong.
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.
Sorry, something went wrong.
There was a problem hiding this comment.
done.
Sorry, something went wrong.
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.
a -> an
Sorry, something went wrong.
These changes are just some grammatical changes like using `an` not `a` and space after period etc.
|
LGTM |
Sorry, something went wrong.
|
LGTM |
Sorry, something went wrong.
|
So sad... we'll have to change our code... |
Sorry, something went wrong.
|
@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). |
Sorry, something went wrong.
|
@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 argv[0]=='node' but now we'll have to extract the executable name, perhaps remove the extension (somepath/node.exe on Windows and I guess it's just somepath/node on Linux) and all that stuff. |
Sorry, something went wrong.
|
@Dmitry-Me Checking argv[0] == 'node' wouldn’t be very reliable anyway, e.g. it wouldn’t stop anyone from giving using the full node path as the first argument. If you really need some kind of check, you could test for e.g. the presence of the global process object. |
Sorry, something went wrong.
|
@addaleax Would just checking for presence of process be enough? |
Sorry, something went wrong.
|
@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 node or not (including testing process, module or require). 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). |
Sorry, something went wrong.
| 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?
Sorry, something went wrong.
There was a problem hiding this comment.
Done 👍
Sorry, something went wrong.
|
LGTM with a nit. |
Sorry, something went wrong.
|
LGTM |
Sorry, something went wrong.
|
What's next? |
Sorry, something went wrong.
|
Landed in 475dc43, thank for the contribution! |
Sorry, something went wrong.
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>
| Back | FazBrowse Home | New Git URL |
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]