How to use portfinder

Comprehensive portfinder code examples:

How to use portfinder.getPortPromise:

1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
    return true;
}

async _reservePorts() {
    const [wsPort, ...workerPorts] = await Promise.all([
        portfinder.getPortPromise({ host: "127.0.0.1", port: 9944 }),
        ...this.workers.map((w, i) => portfinder.getPortPromise({ host: "127.0.0.1", port: 8100 + i * 10 }))
    ]);
    this.wsPort = wsPort;
    this.workers.forEach((w, i) => w.port = workerPorts[i]);

How to use portfinder.getPort:

67
68
69
70
71
72
73
74
75
76
77
  ]
})


module.exports = new Promise((resolve, reject) => {
  portfinder.basePort = process.env.PORT || config.dev.port
  portfinder.getPort((err, port) => {
    if (err) {
      reject(err)
    } else {
      // publish the new Port, necessary for e2e tests