erikvold
erikvold

Reputation: 16538

Passing args to a JS command line utility (Node or Narwhal)

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

Answers (4)

sgmonda
sgmonda

Reputation: 2729

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

Upvotes: 0

generalhenry
generalhenry

Reputation: 17319

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

Upvotes: 2

meder omuraliev
meder omuraliev

Reputation: 186662

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

Docs

Upvotes: 2

Jörg W Mittag
Jörg W Mittag

Reputation: 369556

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

Upvotes: 4

Related Questions