0

I would like to run my node script and pass a parameter to this node script

for example my node script index.js looks like :

var user = "me";
console.log(user);

and I would like the user to be a parameter instead of using

node index.js

I can use node index.js --user foo and the parameter pass to the script

Do you have any idea what I should use

Stranger B.
  • 9,004
  • 21
  • 71
  • 108
  • 4
    Possible duplicate of [How do I pass command line arguments to Node.js?](http://stackoverflow.com/questions/4351521/how-do-i-pass-command-line-arguments-to-node-js) – Sal Rahman Sep 07 '16 at 20:36

1 Answers1

1

It seems as though you are trying to pass command line arguments in Node. Check out this for multiple explanations on how to do that: How do I pass command line arguments? Seems like this would do if you only have one argument:

var user = process.args.slice(2)
console.log(user);
Community
  • 1
  • 1