How to use the portfinder.getPorts 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 urbanairship / frock / tests / api-integration / index.js View on Github external
test(`setup ${__filename}`, t => {
  t.plan(1)

  frockfile = JSON.parse(fs.readFileSync(path.join(__dirname, 'frockfile.json')))

  portfinder.getPorts(3, (err, foundPorts) => {
    if (err) {
      t.fail(err)
    }

    ports = foundPorts

    // mangle the found ports into the loaded frockfile
    frockfile.servers[0].port = ports[0]
    frockfile.servers[1].port = ports[1]
    frockfile.sockets[0].port = ports[2]

    frock = lib(frockfile, {pwd})

    frock.run(err => {
      if (err) {
        t.fail(err)
github libp2p / js-libp2p-switch / test / circuit-relay.node.js View on Github external
before((done) => createInfos(5, (err, infos) => {
      expect(err).to.not.exist()

      getPorts(6, (err, ports) => {
        expect(err).to.not.exist()

        bootstrapPeer = infos[0]
        tcpPeer1 = infos[1]
        tcpPeer2 = infos[2]
        wsPeer1 = infos[3]
        wsPeer2 = infos[4]

        // Setup the addresses of our nodes
        bootstrapPeer.multiaddrs.add(`/ip4/0.0.0.0/tcp/${ports.shift()}`)
        bootstrapPeer.multiaddrs.add(`/ip4/0.0.0.0/tcp/${ports.shift()}/ws`)
        tcpPeer1.multiaddrs.add(`/ip4/0.0.0.0/tcp/${ports.shift()}`)
        tcpPeer2.multiaddrs.add(`/ip4/0.0.0.0/tcp/${ports.shift()}`)
        wsPeer1.multiaddrs.add(`/ip4/0.0.0.0/tcp/${ports.shift()}/ws`)
        wsPeer2.multiaddrs.add(`/ip4/0.0.0.0/tcp/${ports.shift()}/ws`)
github yyssc / ssc-grid / docs / dev-run.js View on Github external
return;
    })
    .then(() => console.log('Shutdown: '.cyan + name.green))
    .catch(err => {
      if (catchExec(name, err)) {
        // Restart if not explicitly shutdown
        runCmd(name, cmd, options);
      }
    });
}

console.log('Starting docs in Development mode'.cyan);

process.on(SIGINT, shutdown);

portfinder.getPorts(2, {}, (portFinderErr, [docsPort, webpackPort]) => {
  if (portFinderErr) {
    console.log('Failed to acquire ports'.red);
    process.exit(1);
  }

  // runCmd('webpack-dev-server', `nodemon --watch webpack --watch webpack.docs.js --exec webpack-dev-server -- --config webpack.docs.js --color --port ${webpackPort} --debug --hot --host ${ip.address()}`);
  runCmd('webpack-dev-server', `nodemon --watch webpack --watch webpack.docs.js --exec webpack-dev-server -- --config webpack.docs.js --color --port ${webpackPort} --debug --hot --host 127.0.0.1`);

  runCmd('docs-server', 'nodemon --watch docs --watch src --exec babel-node docs/server.js', {
    env: {
      PORT: docsPort,
      WEBPACK_DEV_PORT: webpackPort,
      ...process.env
    }
  });
});
github react-bootstrap / react-bootstrap / docs / dev-run.js View on Github external
processMap[name] = childProcess;
    })
    .then(() => console.log('Shutdown: '.cyan + name.green))
    .catch((err) => {
      if (catchExec(name, err)) {
        // Restart if not explicitly shutdown
        runCmd(name, cmd, options);
      }
    });
}

console.log('Starting docs in Development mode'.cyan);

process.on(SIGINT, shutdown);

portfinder.getPorts(2, {}, (portFinderErr, [docsPort, webpackPort]) => {
  if (portFinderErr) {
    console.log('Failed to acquire ports'.red);
    process.exit(1);
  }

  runCmd('webpack-dev-server', `nodemon --watch webpack --watch webpack.docs.js --exec webpack-dev-server -- --config webpack.docs.js --color --port ${webpackPort} --debug --hot --host ${ip.address()}`);

  runCmd('docs-server', 'nodemon --watch docs --watch src --exec babel-node docs/server.js', {
    env: {
      PORT: docsPort,
      WEBPACK_DEV_PORT: webpackPort,
      ...process.env,
    },
  });
});

portfinder

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

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis