How to use tcp-port-used - 10 common examples

To help you get started, we’ve selected a few tcp-port-used 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 mozilla-b2g / fxos-device-service / test / setup.js View on Github external
suiteSetup(async function() {
  chai.should();

  service.start({
    port: 3000,
    // Make sure that our fake adb gets used instead of the real thing.
    adbPath: path.resolve(__dirname, './adb')
  });

  await tcpPortUsed.waitUntilUsed(3000);
});
github ovh / manager / scripts / webpack-cypress.js View on Github external
fp(3000, (err, port) => {
  const webpackApp = execa('yarn', ['start:dev', '--port', port]);
  webpackApp.stdout.pipe(process.stdout);

  tcpPortUsed.waitUntilUsed(port, 500, 1000 * 60 * 5)
    .then(() => {
      const cypressShell = execa('cypress', ['run', '--config', `baseUrl=http://localhost:${port}`]);
      cypressShell.stdout.pipe(process.stdout);
      return cypressShell;
    })
    .then(() => kill(port))
    .then(() => process.exit(0))
    .catch((err) => { console.error(err); process.exit(1); }); // eslint-disable-line no-shadow
});
github Financial-Times / x-dash / athloi.js View on Github external
run(options) {
			const openUrl = openUrls[options.open];
			const port = parseInt(url.parse(openUrl).port, 10);

			if(port) {
				// wait for whatever (storybook/gatsby) to be listening on the port
				// try every 500ms and give up after 30s
				tcpPortUsed.waitUntilUsed(port, 500, 30000)
					.then(() => open(openUrl))
					.catch(e => console.error(e.stack));
			}

			return tasks.start.run(options);
		},
	}),
github Marus / cortex-debug / src / tcpportscanner.ts View on Github external
{
                min: number;			// Starting port number
                max: number;			// Ending port number (inclusive)
                retrieve?: number;		// Number of ports needed
                consecutive?: boolean;
                doLog?: boolean;
            },
        host = TcpPortScanner.DefaultHost, cb = null): Promise {
        let freePorts = [];
        const busyPorts = [];
        const needed = retrieve;
        let error = null;
        if (needed <= 0) {
            return new Promise((resolve) => { resolve(freePorts); });
        }
        const functor = TcpPortScanner.shouldUseServerMethod(host) ? TcpPortScanner.isPortInUseEx : tcpPortUsed.tcpPortUsed;
        for (let port = min; port <= max; port++) {
            if (needed <= 0) {
                return;
            }
            const startTime = process.hrtime();
            await functor(port, host)
                .then((inUse) => {
                    const endTime = process.hrtime(startTime);
                    if (inUse) {
                        busyPorts.push(port);
                    } else {
                        if (consecutive && (freePorts.length > 0) &&
                            (port !== (1 + freePorts[freePorts.length - 1]))) {
                            if (doLog) {
                                console.log('TcpPortHelper.finnd: Oops, reset for consecutive requirement');
                            }
github aws / aws-toolkit-vscode / src / shared / codelens / localLambdaRunner.ts View on Github external
export async function waitForDebugPort(
    debugPort: number,
    timeoutDuration: number,
    channelLogger: ChannelLogger
): Promise {
    try {
        // this function always attempts once no matter the timeoutDuration
        await tcpPortUsed.waitUntilUsed(debugPort, SAM_LOCAL_PORT_CHECK_RETRY_INTERVAL_MILLIS, timeoutDuration)
    } catch (err) {
        getLogger().warn(`Timed out after ${timeoutDuration} ms waiting for port ${debugPort} to open`, err as Error)

        channelLogger.warn(
            'AWS.samcli.local.invoke.port.not.open',
            // tslint:disable-next-line:max-line-length
            "The debug port doesn't appear to be open. The debugger might not succeed when attaching to your SAM Application."
        )
    }
}
github LimeChain / etherlime / test / etherlime / cli-commands / ganache / ganache.js View on Github external
it('should run ganache server on passed port', async () => {
			childResponse = await runCmdHandler(`etherlime ganache --port ${RUN_DIRECT_PORT}`, expectedOutput);

			const portInUseAfterDirectCallRun = await tcpPortUsed.check(RUN_DIRECT_PORT);

			assert.isTrue(portInUseAfterDirectCallRun, `The specific port ${RUN_DIRECT_PORT} is free`);

		});
	});
github Alfresco / Aikau / aikau / resources / grunt / testing.js View on Github external
grunt.registerTask("startUnitTestApp", "Spawn a Maven process to start the Jetty server running the unit test application", function() {
      grunt.log.writeln("Check Jetty unit test application state...");
      var done = this.async();
      tcpPortUsed.check(8089, "localhost")
         .then(function(inUse) {
            if (!inUse) {
               grunt.log.writeln("Starting unit test app...");
               grunt.task.run("shell:startTestApp");
               done();
            } else {
               grunt.log.writeln("Jetty unit test application appears to be running already...");
               done();
            }
         }, function(err) {
            console.error("Unknown if Jetty unit test application is already running:", err.message);
            done();
         });
   });
github lambdabaa / dav / test / integration / server / bootstrap.js View on Github external
'127.0.0.1:8888',
    'calendarserver.php'
  ], {
    cwd: __dirname + '/SabreDAV'
  });

  server.stdout.on('data', function(chunk) {
    debug(chunk.toString());
  });

  server.stderr.on('data', function(chunk) {
    debug(chunk.toString());
  });

  debug('Wait for dav server to start.');
  return tcpPortUsed.waitUntilUsed(8888, 100, 20000);
});
github mozilla-b2g / fxos-device-service / test / setup.js View on Github external
suiteTeardown(async function() {
  service.stop();
  await tcpPortUsed.waitUntilFree(3000);
});
github blockapps / blockapps-rest / util / oauth-token-getter / index.js View on Github external
(async() => {
  if (await tcpPortUsed.check(+port)) {
    console.error(`ERROR: Port ${port} is in use.`);
    process.exit(3)
  }
  if (port+'' === '443') {
    https.createServer({
      key: DUMMY_SSL_KEY,
      cert: DUMMY_SSL_CERT
    }, app)
        .listen(port, function () {
          console.log(`App listening on port ${port}.`)
        });
  } else {
    app.listen(port, function () {
      console.log(`App listening on port ${port}.`)
    });
  }

tcp-port-used

A simple Node.js module to check if a TCP port is already bound.

MIT
Latest version published 4 years ago

Package Health Score

70 / 100
Full package analysis