0

I want to do an npm install in a ton of directories.

Can I create a shell script that will run npm install in all of them asynchronously? So I don't have to wait long for all of them to be done?

IE

cd foo; npm install; cd ..; cd bar; npm install; cd ..; etc.

1
  • 1
    start npm install, basically Commented Nov 5, 2015 at 18:35

1 Answer 1

2

You can run them in the background using & at the end:

cd foo && npm install &
cd bar && npm install &

There's no need for cd .. here because each line runs in a separate child process. Also I'm using && here instead of ;, otherwise you'd need to add () to group the commands:

( cd foo; npm install ) &
( cd bar; npm install ) &

As a plus, && will not execute commands to it's right if the command to it's left fails.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.