Home > Mobile >  How to run several js files at once?
How to run several js files at once?

Time:02-13

I've created simple tool that I would like to work daily to get new data everyday. I have few js files that I would like to run at once. Instead of manually typing in terminal:

node news.js 
node main.js
node weather.js

Can I automate it somehow to type one command and everything runs automatically when previous file finished task?

Thanks

CodePudding user response:

Chain the commands:

node news.js && node main.js && node weather.js

By using the && operator you are instructing the system to wait for the end of the first command to run the second. The second command will only run if the first ends with status code 0 and the third will only run if the second also ends with status 0.

Exit status 0 indicates the command finished successfully.

If you don't need the first command to finish successfully you could replace the '&&' with ';' to continue anyway despite error status. If you are on Windows the ; operator doesn't work on command prompt but it does with Powershell.

If you rather want to run them in parallel you could also use:

node news.js & node main.js & node weather.js
  • Related