How to use the portfinder.highestPort 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 kalisio / feathers-distributed / src / index.js View on Github external
masterTimeout: 60000,
      log: (process.env.COTE_LOG ? true : false),
      basePort: (process.env.BASE_PORT ? Number(process.env.BASE_PORT) : 10000),
      highestPort: (process.env.HIGHEST_PORT ? Number(process.env.HIGHEST_PORT) : 20000)
    }, options.cote)
    app.distributionOptions = Object.assign({
      publicationDelay: (process.env.PUBLICATION_DELAY ? Number(process.env.PUBLICATION_DELAY) : 10000),
      coteDelay: (process.env.COTE_DELAY ? Number(process.env.COTE_DELAY) : undefined),
      middlewares: {},
      publishEvents: true
    }, options)

    debug('Initializing feathers-distributed with options', app.distributionOptions)
    // Change default base/highest port for automated port finding
    portfinder.basePort = app.coteOptions.basePort
    portfinder.highestPort = app.coteOptions.highestPort
    // We need to uniquely identify the app to avoid infinite loop by registering our own services
    app.uuid = uuid()
    // Setup cote with options and required delay
    if (app.distributionOptions.coteDelay) setTimeout(_ => { initializeCote(app) }, app.distributionOptions.coteDelay)
    else initializeCote(app)

    // We replace the use method to inject service publisher/responder
    const superUse = app.use
    app.use = function () {
      const path = arguments[0]
      // Register the service normally first
      const superReturn = superUse.apply(app, arguments)
      // Check if cote has already been initialized
      if (!app.cote) return superReturn
      // With express apps we can directly register middlewares: not supported
      if (typeof path !== 'string') return superReturn
github umijs / umi / packages / umi-build-dev / src / plugins / commands / dev / getPort.js View on Github external
export default async port => {
  if (port) {
    return port;
  }
  if (process.env.PORT) {
    return parseInt(process.env.PORT, 10);
  }

  portfinder.basePort = parseInt(process.env.BASE_PORT) || 8000;
  portfinder.highestPort = portfinder.basePort + 1000;

  return portfinder.getPortPromise();
};
github umijs / umi / packages / umi-ui-tasks / src / server / util / stats.ts View on Github external
const getAvailablePort = async () => {
  portfinder.basePort = 8888;
  portfinder.highestPort = 9999;

  return await portfinder.getPortPromise();
};

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