How to use the portfinder.getPortPromise 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 KuangPF / vue-cli-analysis / packages / @vue / cli-service / lib / commands / serve.js View on Github external
}

    // entry arg
    const entry = args._[0]
    if (entry) {
      webpackConfig.entry = {
        app: api.resolve(entry)
      }
    }

    // resolve server options
    const useHttps = args.https || projectDevServerOptions.https || defaults.https
    const protocol = useHttps ? 'https' : 'http'
    const host = args.host || process.env.HOST || projectDevServerOptions.host || defaults.host
    portfinder.basePort = args.port || process.env.PORT || projectDevServerOptions.port || defaults.port
    const port = await portfinder.getPortPromise()
    const rawPublicUrl = args.public || projectDevServerOptions.public
    const publicUrl = rawPublicUrl
      ? /^[a-zA-Z]+:\/\//.test(rawPublicUrl)
        ? rawPublicUrl
        : `${protocol}://${rawPublicUrl}`
      : null

    const urls = prepareURLs(
      protocol,
      host,
      port,
      isAbsoluteUrl(options.baseUrl) ? '/' : options.baseUrl
    )

    const proxySettings = prepareProxy(
      projectDevServerOptions.proxy,
github bbhj / mina / build / dev-server.js View on Github external
module.exports = new Promise((resolve, reject) => {
  portfinder.basePort = port
  portfinder.getPortPromise()
  .then(newPort => {
      if (port !== newPort) {
        console.log(`${port}端口被占用,开启新端口${newPort}`)
      }
      var server = app.listen(newPort, 'localhost')
      // for 小程序的文件保存机制
      require('webpack-dev-middleware-hard-disk')(compiler, {
        publicPath: webpackConfig.output.publicPath,
        quiet: true
      })
      resolve({
        ready: readyPromise,
        close: () => {
          server.close()
        }
      })
github open-wc / open-wc / packages / es-dev-server / src / start-server.js View on Github external
export async function startServer(cfg, fileWatcher = chokidar.watch([])) {
  const result = createServer(cfg, fileWatcher);
  const { app } = result;
  let { server } = result;

  const port = typeof cfg.port === 'number' ? cfg.port : await portfinder.getPortPromise();

  // cleanup after quit
  function closeFileWatcher() {
    if (fileWatcher) {
      fileWatcher.close();
      /* eslint-disable-next-line no-param-reassign */
      fileWatcher = undefined;
    }
  }

  server.addListener('close', closeFileWatcher);

  function stopServer() {
    if (server) {
      server.close();
      server = undefined;
github DonJayamanne / pythonVSCode / src / client / common / application / webPanels / webPanelProvider.ts View on Github external
private async ensureServerIsRunning(): Promise<{ port: number; token: string }> {
        if (!this.port || !this.token) {
            // Compute a usable port.
            this.port = await portfinder.getPortPromise({ startPort: 9000, port: 9000 });
            this.token = uuid();

            // Import webpanel server dynamically so doesn't load in the main extension until we
            // get to here.
            // tslint:disable-next-line:no-require-imports
            const webPanelServerModule = require('./webPanelServer') as typeof import('./webPanelServer');

            // Start the server listening.
            const webPanelServer = new webPanelServerModule.WebPanelServer(this.port, this.token, this.fs);
            webPanelServer.start();
            this.disposableRegistry.push(webPanelServer);
        }

        return { port: this.port, token: this.token };
    }
}
github VoxaAI / voxa / test / create-server.spec.js View on Github external
before(() => {
    const skill = new StateMachineApp({ views });
    const adapter = new AlexaAdapter(skill);
    server = createServer(adapter);
    return portfinder.getPortPromise()
      .then((_port) => {
        port = _port;
        server.listen(port, () => debug(`Listening on ${port}`));
      });
  });
github basys / basys / packages / basys / lib / index.js View on Github external
async function start(projectDir, appName, env = 'prod') {
  const config = getConfig(projectDir, appName, env);
  if (config.type === 'web') {
    const backendPath = path.join(config.distDir, 'backend.js');
    if (!fs.pathExistsSync(backendPath)) {
      exit(`Please run \`basys build${appName ? ` ${appName}` : ''}\` command first`);
    }

    const port = await portfinder.getPortPromise({host: config.host, port: config.port});
    config.port = port;
    config.backendPort = port;
    await fs.ensureDir(config.distDir);
    await fs.writeFile(path.join(config.distDir, 'config.json'), JSON.stringify({port}));

    require(backendPath);

    console.log(`Your application is available at http://${config.host}:${port}`);
  }
  return config;
}
github haxzie-xx / slidex / index.js View on Github external
isPortTaken(port).then((isAvailable) => {

    if (isAvailable) {
        runServer(port);
    } else {
        //get an unused open port in the system
        console.log('Port '+port+' is already in use, Fetching new port...');
        portfinder.getPortPromise()
        .then((port) => {
            runServer(port);
        })
        .catch((err) => {
            console.log("Unable to start the server : "+err);
        })
    }
}).catch((err) => {
    console.log(err);
github jsayol / vscode-firebase-explorer / src / emulators / server.ts View on Github external
function getRandomPort(host: string): Promise<number> {
  return portfinder.getPortPromise({ host, port: PORT_START });
}
github atomist / automation-client / lib / util / port.ts View on Github external
export function scanFreePort(start: number = 2866, end: number = 2888): Promise<number> {
    return portfinder.getPortPromise({ port: start, stopPort: end });
}
github d-fischer / twitch / packages / twitch-webhooks / src / WebHookListener.ts View on Github external
static async create(client: TwitchClient, config: WebHookListenerConfig = {}) {
		const listenerPort = config.port || (await portFinder.getPortPromise());
		const reverseProxy = config.reverseProxy || {};
		return new WebHookListener(
			{
				hostName: config.hostName || (await publicIp.v4()),
				port: listenerPort,
				ssl: config.ssl,
				reverseProxy: {
					port: reverseProxy.port || listenerPort,
					ssl: reverseProxy.ssl === undefined ? !!config.ssl : reverseProxy.ssl,
					pathPrefix: reverseProxy.pathPrefix || ''
				},
				hookValidity: config.hookValidity
			},
			client
		);
	}

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