0

I am trying to specify 2 arguments with express JS start command, as specified below:

npm start -x 5 -y 43

But in doing so, I can't pick the arguments with '-' and they are somehow skipped in the following code.

process.argv.forEach(function (val, index, array) {
    log.info(index + ': ' + val);
    log.error("========="+array[index].toString());
});

Please help me to get the arguments with '-' as initials?

Note: I have tried using Yarks, but its not working as specified in the manual.

2 Answers 2

4

To pass arguments in npm script you must use double dash --:

npm start -- -x 5 -y 43

Check npm-run-script command documentation for more details.

Sign up to request clarification or add additional context in comments.

9 Comments

It actually worked for the first '-x' but the it didn't worked for the second '-y'. I had to add one more '--' in front of the '-y'. Do you have any solution for this?
What doesn't work for you? Remember that with this declartion: -x 5 -y 43, you'll get 5 arguments: filename, x, 5, y, 43, node docs
The first argument is a process filename.
How is your start script looks?
You pass arguments from npm start not in node process, bun in nodemon process. This process runs node process and pass to it own arguments. To check that npm correctly pass arguments, use script which runs node process: "scripts": { "start": "node app.js }, for example.
|
-1

I was able to pass in arguments with simply

npm start myArg1 myArg2

Both bin/www and app.js could access them.

1 Comment

The OP is looking for ways to mitigate the '-' in the arguments which the node doesn't seem to pick up while running.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.