Skip to content
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

Closed
wants to merge 7 commits into from

Conversation

tarungarg546
Copy link
Contributor

Checklist
  • documentation is changed or added
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]

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. process Issues and PRs related to the process subsystem. labels Jun 27, 2016
@cjihrig
Copy link
Contributor

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
@@ -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
Copy link
Contributor

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."

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done @cjihrig

@Fishrock123 Fishrock123 changed the title Updated ReadMe for #7434 Fix documentation of process.argv[0] Jun 28, 2016
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.
Copy link
Contributor

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.

Copy link
Contributor Author

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:

Copy link
Contributor

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?

Copy link
Contributor Author

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()`],
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.
@cjihrig
Copy link
Contributor

cjihrig commented Jun 29, 2016

LGTM

1 similar comment
@mscdex
Copy link
Contributor

mscdex commented Jun 29, 2016

LGTM

@Dmitry-Me
Copy link

So sad... we'll have to change our code...

@addaleax
Copy link
Member

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
Copy link

@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.

@addaleax
Copy link
Member

addaleax commented Jul 1, 2016

@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.

@Dmitry-Me
Copy link

@addaleax Would just checking for presence of process be enough?

@addaleax
Copy link
Member

addaleax commented Jul 1, 2016

@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).

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
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

@addaleax
Copy link
Member

addaleax commented Jul 1, 2016

LGTM with a nit.

@jasnell
Copy link
Member

jasnell commented Jul 1, 2016

LGTM

@tarungarg546
Copy link
Contributor Author

What's next?

@addaleax
Copy link
Member

addaleax commented Jul 4, 2016

Landed in 475dc43, thank for the contribution!

@addaleax addaleax closed this Jul 4, 2016
addaleax pushed a commit that referenced this pull request Jul 4, 2016
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]>
Fishrock123 pushed a commit that referenced this pull request Jul 5, 2016
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]>
@Fishrock123 Fishrock123 mentioned this pull request Jul 5, 2016
ppannuto added a commit to ppannuto/node that referenced this pull request Aug 1, 2016
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`
addaleax pushed a commit that referenced this pull request Aug 8, 2016
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]>
cjihrig pushed a commit that referenced this pull request Aug 10, 2016
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. process Issues and PRs related to the process subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants