Node.js: process.argv vs. process.ARGV
Asked Answered
T

2

11

I notice that Node defines both process.argv and process.ARGV (capitalized). The later isn't mentioned in the documentation and is, in every case I've encountered so far, the same object.

Is ARGV just a historic holdover, or does it have a purpose?

Tengdin answered 28/4, 2011 at 22:14 Comment(0)
K
10

process.ARGV has been removed entirely since v0.5.10.

Karyolysis answered 5/2, 2013 at 22:45 Comment(1)
Can't argue with commits. :)Tengdin
V
4

They are identical:

node.cc

// process.argv
Local<Array> arguments = Array::New(argc - option_end_index + 1);
arguments->Set(Integer::New(0), String::New(argv[0]));
for (j = 1, i = option_end_index; i < argc; j++, i++) {
  Local<String> arg = String::New(argv[i]);
  arguments->Set(Integer::New(j), arg);
}
// assign it
process->Set(String::NewSymbol("ARGV"), arguments);
process->Set(String::NewSymbol("argv"), arguments);

Edit (based on further question):

There's only one person who can tell you that for sure (the author) - you might be able to find him on IRC (irc.freenode.net #node.js).

Looking through the other symbols, I'd guess that it was added for consistency - argv and env seem to be the only two that have both lower and upper case versions. However, ENV differs slightly from env. Maybe the author thought that argv and ARGV might differ in the same manner as env and ENV?

Virginavirginal answered 28/4, 2011 at 22:25 Comment(4)
node warns you every time you use process.ENV: Use process.env instead of process.ENV. Presumably these are deprecated but kept for backwards compatibility.Merle
@ricardo: cool, didn't dig that far through the source.. +1 :)Virginavirginal
I just remembered seeing that message :) turns out they are really deprecated: github.com/joyent/node/pull/372Merle
It is easy to get this confused, especially if you ever use spidermonkey. gjs uses ARGV and not process.argv. Fun fact.Leninism

© 2022 - 2024 — McMap. All rights reserved.