4

I want to use NodeJS or Narwhal to create a JS utility which takes an argument, like so:

$ node myscript.js http://someurl.com/for/somefile.js

or

$ js myscript.js http://someurl.com/for/somefile.js

but I'm wondering how I can get that argument within my script, or if that is even possible atm?

Thanks.

erikvold
  • 15,988
  • 11
  • 54
  • 98

4 Answers4

4

On Node.JS, that information is available in process.argv.

Community
  • 1
  • 1
Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
2

process.arg[2] should be the reference. Check for process.argv.length to see if it's 3.

Docs

meder omuraliev
  • 183,342
  • 71
  • 393
  • 434
2

You can use optimist, a module for node.js that makes processing args a bit easier.

generalhenry
  • 17,227
  • 4
  • 48
  • 63
0

This things now are very easy to do, using stdio module for NodeJS.

sgmonda
  • 2,615
  • 1
  • 19
  • 29