Stranger B.
Stranger B.

Reputation: 9364

How to run node script with a parameter

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

Upvotes: 0

Views: 288

Answers (1)

user3624901
user3624901

Reputation:

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);

Upvotes: 1

Related Questions