Reputation: 16538
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.
Upvotes: 4
Views: 397
Reputation: 2729
This things now are very easy to do, using stdio module for NodeJS.
Upvotes: 0
Reputation: 17319
You can use optimist, a module for node.js that makes processing args a bit easier.
Upvotes: 2
Reputation: 186662
process.arg[2]
should be the reference. Check for process.argv.length
to see if it's 3
.
Upvotes: 2
Reputation: 369556
On Node.JS, that information is available in process.argv
.
Upvotes: 4