简体   繁体   中英

Can node js pass command line arguments to twojs in the same line?

I am new to Node.js. Recently, I am building a script as below:

"updateData": "node runFirstScript.js && node runSecondScript.js",
"build:desktop": "npm run updateData env1",
"build:mobile": "npm run updateData env2",

I am expecting runFirstScript.js and runSecondScript.js can get the parameters env1 and env2 while they are executed.

Instead of separating as below:

"updateData1": "node runFirstScript.js",
"updateData2": "node runFirstScript.js",
"build:desktop": "npm run updateData1 env1 && npm run updateData2 env1",
"build:mobile": "npm run updateData1 env2 &&  npm run updateData2 env2",

Is there any optimum solution for this? Thanks

Just change && to & ,here is the reason what each symbol mean:

  • & is to make the command run in background. You can execute more than one command in the background, in a single go. For eg: Command1 & Command2 & Command3

  • && is to make following commands run only if preceding command succeeds.For eg: Lets say we have Command1 && Command2 && Command3 . Command2 will only execute if Command1 succeed.

  • Bonus: ; which is useful in your daily productivity , You can run several commands in a single go and the execution of command occurs sequentially. For eg: Command1; Command2; Command3 Command1; Command2; Command3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM