How to use the getPortPromise function from portfinder

Find comprehensive JavaScript portfinder.getPortPromise code examples handpicked from public code repositorys.

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]);
fork icon133
star icon319
watch icon0

+ 5 other calls in file

85
86
87
88
89
90
91
92
93
94
95
//   _resolve()
// })


module.exports = new Promise((resolve, reject) => {
  portfinder.basePort = port
  portfinder.getPortPromise()
  .then(newPort => {
      if (port !== newPort) {
        console.log(`${port}端口被占用,开启新端口${newPort}`)
      }
fork icon3
star icon8
watch icon0

47
48
49
50
51
52
53
54
55
await postCheck(opts);

if (server) {
  serverPort = APP_PORT;
} else if (!server && !client) {
  serverPort = await getPortPromise({
    port: 1 * clientPort + 1,
  });
}
fork icon0
star icon1
watch icon1

+ 6 other calls in file

34
35
36
37
38
39
40
41
42
43
var isProd        = false;

if (environment === 'production') { isProd = true; }

portfinder.basePort = (env && env.port) || 1962
return portfinder.getPortPromise().then(port => {
  const plugins = [
    new HtmlWebpackPlugin({ template: "index.html", hash: true, inject: "body" }),
    new BaseHrefWebpackPlugin({ baseHref: basehref }),
    new ExtWebpackPlugin({
fork icon0
star icon1
watch icon1

+ 2 other calls in file

8
9
10
11
12
13
14
15
16
17
18
19
20


const HtmlWebpackPlugin = require('html-webpack-plugin');


module.exports = async function webpackConfig() {
  portfinder.basePort = (process.env.PORT && Number(process.env.PORT)) || config.port;
  const port = await portfinder.getPortPromise();
  const host = process.env.HOST || config.host;


  return merge(baseWebpackConfig, {
    mode: 'development',
fork icon0
star icon0
watch icon0

4
5
6
7
8
9
10
11
12
13
14
15
16


let server = null
let port = null


beforeEach(async () => {
  port = await portfinder.getPortPromise()
  server = app.listen(port)
})


afterEach(() => {
fork icon0
star icon0
watch icon0