Makes sure you get an available port.
npm i ensure-port
yarn add ensure-port
import { Ports } from 'ensure-port';
const ports = new Ports({
startPort: 8000,
endPort: 9000,
});
const port = await ports.ensure(); // This would be a random port between 8000 and 9000 that is not used (validated against file-system and http server)
// When you finish - remove watcher
await ports.dispose();
It saves inside your node_modules
a directory that contain all the ports that are in use.
This is why it works in parallel.
Feel free to fork and create pull requests!