How to use the get-port.makeRange function in get-port

To help you get started, we’ve selected a few get-port 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 ipfs-shipyard / ipfs-companion / add-on / src / lib / ipfs-client / embedded-chromesockets.js View on Github external
dht: {
        // TODO: check if below is needed after js-ipfs is released with DHT disabled
        enabled: false
      }
    }
  }
  const userOpts = JSON.parse(opts.ipfsNodeConfig)
  const ipfsNodeConfig = mergeOptions.call({ concatArrays: true }, defaultOpts, userOpts, { start: false })

  // Detect when API or Gateway port is not available (taken by something else)
  // We find the next free port and update configuration to use it instead
  const multiaddr2port = (ma) => parseInt(new URL(multiaddr2httpUrl(ma)).port, 10)
  const gatewayPort = multiaddr2port(ipfsNodeConfig.config.Addresses.Gateway)
  const apiPort = multiaddr2port(ipfsNodeConfig.config.Addresses.API)
  log(`checking if ports are available: api: ${apiPort}, gateway: ${gatewayPort}`)
  const freeGatewayPort = await getPort({ port: getPort.makeRange(gatewayPort, gatewayPort + 100) })
  const freeApiPort = await getPort({ port: getPort.makeRange(apiPort, apiPort + 100) })
  if (gatewayPort !== freeGatewayPort || apiPort !== freeApiPort) {
    log(`updating config to available ports: api: ${freeApiPort}, gateway: ${freeGatewayPort}`)
    const addrs = ipfsNodeConfig.config.Addresses
    addrs.Gateway = addrs.Gateway.replace(gatewayPort.toString(), freeGatewayPort.toString())
    addrs.API = addrs.API.replace(apiPort.toString(), freeApiPort.toString())
  }

  return ipfsNodeConfig
}
github himynameisdave / svb / lib / rollup.js View on Github external
const getPlugins = async ({
  input,
  output,
  isDevelopmentMode,
}) => {
  const inputFolder = path.dirname(input);
  const port = await getPort({
    port: getPort.makeRange(3000, 3100),
  });
  return isDevelopmentMode
    //  Dev plugins
    ? [
      sourcemaps(),
      serve({
        // Launch in browser
        open: true,
        contentBase: output,
        port,
        verbose: true,
      }),
      livereload({
        watch: [
          output,
          inputFolder,
github opticdev / optic / api-cli / src / commands / spec.ts View on Github external
const specFileExists = await fs.pathExists(specStorePath)

    if (specFileExists) {
      try {
        const specFileContents = await fs.readJson(specStorePath)
        if (!Array.isArray(specFileContents)) {
          throw new Error('not array')
        }
      } catch (e) {
        return this.error(fromOptic('It looks like there is something wrong with your API spec file. Please make sure it is a valid JSON array.'))
      }
    }

    await emitGitState()

    const port = await getPort({port: getPort.makeRange(3201, 3299)})
    const sessionUtilities = new SessionUtilities(sessionsPath)
    const sessionValidatorAndLoader = new FileSystemSessionValidatorAndLoader(sessionUtilities)
    const paths = await getPaths()
    await startServer(paths, sessionValidatorAndLoader, port, config)

    const url = `http://localhost:${port}/`
    this.log(fromOptic('Displaying your API Spec at ' + url))
    await open(url)
    await cli.wait(1000)
    await cli.anykey('Press any key to exit')
    return process.exit()
  }
}
github sitespeedio / browsertime / lib / core / engine / index.js View on Github external
async start() {
    this.options.devToolsPort = await getPort({
      port: getPort.makeRange(9222, 9350),
      host: '127.0.0.1'
    });

    if (get(this.options, 'connectivity.tsproxy.port') === undefined) {
      set(
        this.options,
        'connectivity.tsproxy.port',
        await getPort({
          port: getPort.makeRange(1080, 1099),
          host: '127.0.0.1'
        })
      );
    }
    if (!this.options.connectivity.variance) {
      await addConnectivity(this.options);
    }
    return Promise.all([this.myXVFB.start(), this.myExtensionServer.start()]);
  }
github IPSE-TEAM / ipse-desktop / src / daemon / daemon.js View on Github external
const configApiMa = parseCfgMultiaddr(config.Addresses.API)
  const configGatewayMa = parseCfgMultiaddr(config.Addresses.Gateway)

  const isApiMaDaemon = await checkIfAddrIsDaemon(configApiMa.nodeAddress())
  const isGatewayMaDaemon = await checkIfAddrIsDaemon(configGatewayMa.nodeAddress())

  if (isApiMaDaemon && isGatewayMaDaemon) {
    logger.info('[daemon] ports busy by a daemon')
    return
  }

  const apiPort = parseInt(configApiMa.nodeAddress().port, 10)
  const gatewayPort = parseInt(configGatewayMa.nodeAddress().port, 10)

  const freeGatewayPort = await getPort({ port: getPort.makeRange(gatewayPort, gatewayPort + 100) })
  const freeApiPort = await getPort({ port: getPort.makeRange(apiPort, apiPort + 100) })

  const busyApiPort = apiPort !== freeApiPort
  const busyGatewayPort = gatewayPort !== freeGatewayPort

  if (!busyApiPort && !busyGatewayPort) {
    return
  }

  let message = null
  let options = null

  if (busyApiPort && busyGatewayPort) {
    logger.info('[daemon] api and gateway ports busy')
    message = 'busyPortsDialog'
    options = {
      port1: apiPort,
github ipfs-shipyard / ipfs-desktop / src / daemon / config.js View on Github external
const configApiMa = parseCfgMultiaddr(config.Addresses.API)
  const configGatewayMa = parseCfgMultiaddr(config.Addresses.Gateway)

  const isApiMaDaemon = await checkIfAddrIsDaemon(configApiMa.nodeAddress())
  const isGatewayMaDaemon = await checkIfAddrIsDaemon(configGatewayMa.nodeAddress())

  if (isApiMaDaemon && isGatewayMaDaemon) {
    logger.info('[daemon] ports busy by a daemon')
    return
  }

  const apiPort = parseInt(configApiMa.nodeAddress().port, 10)
  const gatewayPort = parseInt(configGatewayMa.nodeAddress().port, 10)

  const freeGatewayPort = await getPort({ port: getPort.makeRange(gatewayPort, gatewayPort + 100) })
  const freeApiPort = await getPort({ port: getPort.makeRange(apiPort, apiPort + 100) })

  const busyApiPort = apiPort !== freeApiPort
  const busyGatewayPort = gatewayPort !== freeGatewayPort

  if (!busyApiPort && !busyGatewayPort) {
    return
  }

  let message = null
  let options = null

  if (busyApiPort && busyGatewayPort) {
    logger.info('[daemon] api and gateway ports busy')
    message = 'busyPortsDialog'
    options = {
github luigifcruz / weatherdump / gui / src / client / client.jsx View on Github external
(async () => {
        let enginePort = await getPort({
            host: "127.0.0.1",
            port: getPort.makeRange(3050, 3150)
        });
    
        if (global.server === undefined) {
            global.server = new WeatherServer(enginePort);
            global.client = new WeatherClient("localhost", enginePort);
            global.server.startEngine();
        }
    })();
});
github IPSE-TEAM / ipse-desktop / src / daemon / daemon.js View on Github external
for (const addr of addrs) {
    const ma = parseCfgMultiaddr(addr)
    const port = parseInt(ma.nodeAddress().port, 10)

    if (port === 0) {
      continue
    }

    const isDaemon = await checkIfAddrIsDaemon(ma.nodeAddress())

    if (isDaemon) {
      continue
    }

    const freePort = await getPort({ port: getPort.makeRange(port, port + 100) })

    if (port !== freePort) {
      const opt = showDialog({
        title: i18n.t('multipleBusyPortsDialog.title'),
        message: i18n.t('multipleBusyPortsDialog.message'),
        type: 'error',
        buttons: [
          i18n.t('multipleBusyPortsDialog.action'),
          i18n.t('close')
        ]
      })

      if (opt === 0) {
        shell.openItem(join(ipfsd.repoPath, 'config'))
      }
github adobe / athena / src / cluster / index.js View on Github external
(async () => {
      const port = await getPort({port: getPort.makeRange(5000, 5100)});

      this.setPort(port);
      this.createTCPServer();
    })();
  }

get-port

Get an available port

MIT
Latest version published 2 months ago

Package Health Score

85 / 100
Full package analysis