1

NodeJS newbie (this is my first node app). How can I execute commands (from the command line) in order? Like in a queue, one after another. Note that some commands could take several seconds. I would like to do it without blocking node, in an asynchronous way.

Is this what I need: https://www.npmjs.com/package/command-queue

I find strange having to call RUN every time I add a command. I mean, the queue should work always.

Thanks a lot for suggestions.

1 Answer 1

2

The npm package you listed looks reasonable, and it has an async method where you can list the commands one after another:

new CommandQueue()
.async(
    'karma start',
    'webpack-dev-server --hot'
)
.run();
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for reply! I will add commands when a switch is pressed (I would like to use with homebridge), so every time it is pressed, a new command is added in the queue (and commands could take seconds). But, what I don't understand is having to call RUN when I add a new command. Is that normal? Apart from that I guess I have to save the queue in a global variable. What do you think? Thanks.
I don't see what's strange having to call run every time you add a new command. Just make sure you're not calling previous commands over again unless they're necessary. Every time a switch is pressed, is there a variable command to run, like including an on or off flag? In that case you could modify the string(s) inside the async call appropriately.

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.