code: function isAvailable(port) {
      return new Promise((resolve, reject) => {
          const server = net.createServer();
  
          server.unref();
          server.on('error', reject);
          const options = {};
          options.port = port;
          server.listen(options, () => {
              const { port } = server.address();
              server.close(() => {
                  resolve(port);
              });
          });
      });
  }
docs: Passing 0 will get an available random port.