I do not believe npm is the best tool for managing complex relationships between processes.
You will be much better off serving the creation of a node script that uses the node child_process module to control the start and kill of shared processes, possibly using spawn .
Having said this and in the spirit of always trying to provide a direct, useful answer.
You can structure your npm scripts, for example (assuming a bash shell):
scripts:{ runBoth: "npm runA & npm runB", // run tasks A and B in parallel runA: "taskA & TASKA_PID=$!", // run task A and capture its PID into $TASKA_PID runB: "taskB && kill $TASKA_PID" // run task B and if it completes successfully, kill task A using its saved PID }
The only βmagicβ here is this:
source share