How to use the tcp-port-used.check function in tcp-port-used

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 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 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}.`)
    });
  }
github jaruba / PowderPlayer / src / lib / dlna.js View on Github external
checkPort: function(devIp,devPort,cb) {
		if (dlna.checkedPorts && dlna.checkedPorts.length) {
			devResult = dlna.checkedPorts.some(function(el,ij) {
				if (el[0] == devIp && el[1] == devPort) {
//					console.log('Refound: '+devIp+' Port '+devPort+' usage: '+el[2]);
					if (el[2]) cb(true);
					else cb(false);
					return true;
				}
			});
			if (devResult) return;
		}

		if (!dlna.checkedPorts) dlna.checkedPorts = [];

		require('tcp-port-used').check(parseInt(devPort), devIp)
		.then(function(inUse) {
//			console.log('Ip: '+devIp+' Port '+devPort+' usage: '+inUse);
			dlna.checkedPorts.push([devIp,devPort,true]);
			cb(true);
		}, function(err) {
//			console.log('Ip: '+devIp+' Port '+devPort+' Error: '+err.message);
			dlna.checkedPorts.push([devIp,devPort,false]);
			cb(false);
		});
	},
github laurent22 / joplin / ReactNativeClient / lib / ClipperServer.js View on Github external
async findAvailablePort() {
		const tcpPortUsed = require('tcp-port-used');

		let state = null;
		for (let i = 0; i < 10000; i++) {
			state = randomClipperPort(state, Setting.value('env'));
			const inUse = await tcpPortUsed.check(state.port);
			if (!inUse) return state.port;
		}

		throw new Error('All potential ports are in use or not available.');
	}
github laurent22 / joplin / CliClient / app / onedrive-server.js View on Github external
async function main() {
	let api = new OneDriveApi('e09fc0de-c958-424f-83a2-e56a721d331b', 'FAPky27RNWYuXWwThgkQE47');

	let ports = api.possibleOAuthFlowPorts();
	let port = null;
	for (let i = 0; i < ports.length; i++) {
		let inUse = await tcpPortUsed.check(ports[i]);
		if (!inUse) {
			port = ports[i];
			break;
		}
	}

	if (!port) throw new Error('All potential ports are in use - please report the issue at https://github.com/laurent22/joplin');

	let authCodeUrl = api.authCodeUrl('http://localhost:' + port);
	
	let server = http.createServer((request, response) => {
		const query = urlParser.parse(request.url, true).query;

		function writeResponse(code, message) {
			response.writeHead(code, {"Content-Type": "text/html"});
			response.write(message);
github deas / alfresco / root / projects / slingshot / grunt / coverage.js View on Github external
grunt.registerTask('start-node-coverage-server', 'A task to start the node-coverage server (it will stay running)', function() {
      if (!grunt.file.isDir(alf.coverageDirectory))
      {
         grunt.file.mkdir(alf.coverageDirectory);
      }
      
      var tcpPortUsed = require('tcp-port-used');
      tcpPortUsed.check(8082, 'localhost')
      .then(function(inUse) {
         if(!inUse)
         {
            var nodeCoverage = grunt.util.spawn({
               cmd: 'node',
               args: ['node_modules/node-coverage/server.js',
                      '--port',
                      '8082',
                      '--report-dir',
                      alf.coverageDirectory],
               opts: {
                  detached: 'true',
                  stdio : 'inherit'
               }
            }, function(error, result, code) {
               grunt.log.writeln("Finished spawning node-coverage server...");
github titan-suite / ide-alpha / server / src / resolvers / Mutations / deployContract.ts View on Github external
const verifyPortUnused = async (port: number) => {
  const inUse = await tcpPortUsed.check(port, '127.0.0.1')
  if (inUse) {
    server[port].close()
  }
}

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

67 / 100
Full package analysis