How to use the portfinder.getPort function in portfinder

To help you get started, we’ve selected a few portfinder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github smolleyes / StreamStudio / node_modules / peerflix / node_modules / torrent-stream / node_modules / bittorrent-tracker / server.js View on Github external
}
  if (self.listening) throw new Error('server already listening')
  if (onlistening) self.once('listening', onlistening)

  function onPort (err, port) {
    if (err) return self.emit('error', err)
    self.port = port
    // ATTENTION:
    // binding to :: only receives IPv4 connections if the bindv6only
    // sysctl is set 0, which is the default on many operating systems.
    self._httpServer && self._httpServer.listen(port.http || port, '::')
    self._udpSocket && self._udpSocket.bind(port.udp || port)
  }

  if (port) onPort(null, port)
  else portfinder.getPort(onPort)
}
github RyanFleck / Projects / js / React / server-frontend / node_modules / webpack-dev-server / bin / webpack-dev-server.js View on Github external
if (argv.useLocalIp) { options.useLocalIp = true; }

  // Kind of weird, but ensures prior behavior isn't broken in cases
  // that wouldn't throw errors. E.g. both argv.port and options.port
  // were specified, but since argv.port is 8080, options.port will be
  // tried first instead.
  options.port = argv.port === DEFAULT_PORT ? defaultTo(options.port, argv.port) : defaultTo(argv.port, options.port);

  if (options.port != null) {
    startDevServer(webpackOptions, options);
    return;
  }

  portfinder.basePort = DEFAULT_PORT;
  portfinder.getPort((err, port) => {
    if (err) throw err;
    options.port = port;
    startDevServer(webpackOptions, options);
  });
}
github nowa-webpack / nowa / packages / nowa-server / src / index.js View on Github external
if (options.open && !options.openPage) {
      options.openPage = '';
    }

    if (!options.host) {
      options.host = 'localhost';
    }

    if (options.port) {
      startDevServer(finalConfig, options);
      return;
    }

    portfinder.basePort = DEFAULT_PORT;
    portfinder.getPort((err, port) => {
      if (err) throw err;
      options.port = port;
      startDevServer(finalConfig, options);
    });

    function colorInfo(useColor, msg) {
      if (useColor) {
        // Make text blue and bold, so it *pops*
        return `\u001b[1m\u001b[34m${msg}\u001b[39m\u001b[22m`;
      }
      return msg;
    }

    function colorError(useColor, msg) {
      if (useColor) {
        // Make text red and bold, so it *pops*
github samccone / bundle-buddy / server.ts View on Github external
export function launchServer(
  dataPath: string,
  contextPath: string = __dirname
) {
  portfinder.getPort((err: Error, port: number) => {
    if (err != null) {
      console.log(err);
      process.exit(1);
    }
    const app = express();
    app.use(express.static(path.join(contextPath, VIZ_PATH)));
    console.log(path.join(contextPath, VIZ_PATH));
    app.listen(port, "0.0.0.0", () => {
      console.log(`Server running on port ${port}`);
      console.log(`Press Control+C to Quit`);
      opn(`http://localhost:${port}/?file=${dataPath}`);
    });
  });
}
github Redocly / create-openapi-repo / generators / app / templates / _gulpfile.js View on Github external
function edit(done) {
  portfinder.getPort({port: 5000}, function (err, port) {
    var app = connect();
    app.use(swaggerRepo.swaggerEditorMiddleware());
    app.listen(port);
    log(colors.green('swagger-editor started http://localhost:' + port));
  });
  done();
}
github freewheel / dashflow / lib / cli.js View on Github external
return new Promise((resolve, reject) => {
    require("portfinder").getPort({ port: STARTING_PORT }, function(err, port) {
      if (err) {
        reject(err);
      } else {
        resolve(port);
      }
    });
  });
}
github dashersw / cote / dist / components / publisher.js View on Github external
this.sock = new axon.types[this.type]();
    this.sock.sock.on('bind', () => this.startDiscovery());

    const onPort = (err, port) => {
      this.advertisement.port = +port;
      this.sock.bind(port);
      this.sock.sock.server.on('error', err => {
        if (err.code != 'EADDRINUSE') throw err;
        portfinder.getPort({
          host: this.discoveryOptions.address,
          port: this.advertisement.port
        }, onPort);
      });
    };

    portfinder.getPort({
      host: this.discoveryOptions.address,
      port: advertisement.port
    }, onPort);
  }
github dashersw / cote / src / components / monitor.js View on Github external
const onPort = (err, port) => {
            advertisement.port = +port;

            this.sock.bind(port);
            this.sock.sock.server.on('error', (err) => {
                if (err.code != 'EADDRINUSE') throw err;

                portfinder.getPort({
                    host: this.discoveryOptions.address,
                    port: this.advertisement.port,
                }, onPort);
            });
        };

        portfinder.getPort({
            host: this.discoveryOptions.address,
            port: this.advertisement.port,
        }, onPort);
    }
github dashersw / cote / dist / components / monitor.js View on Github external
this.sock.sock.server.on('error', err => {
        if (err.code != 'EADDRINUSE') throw err;
        portfinder.getPort({
          host: this.discoveryOptions.address,
          port: this.advertisement.port
        }, onPort);
      });
    };
github flaviuse / mern-authentication / client / node_modules / webpack-dev-server / bin / webpack-dev-server.js View on Github external
});

    return;
  }

  const options = createConfig(config, argv, { port: DEFAULT_PORT });

  portfinder.basePort = DEFAULT_PORT;

  if (options.port != null) {
    startDevServer(config, options);

    return;
  }

  portfinder.getPort((err, port) => {
    if (err) {
      throw err;
    }

    options.port = port;

    startDevServer(config, options);
  });
}

portfinder

A simple tool to find an open port on the current machine

MIT
Latest version published 6 months ago

Package Health Score

84 / 100
Full package analysis