Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @fibjs/detect-port with all npm packages installed. Try it out:

var detectPort = require("@fibjs/detect-port")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@fibjs/detect-port v1.0.2

JavaScript Implementation of Port Detector

@fibjs/detect-port

NPM version build status appveyor build status Test coverage David deps Known Vulnerabilities npm download

JavaScript Implementation of Port Detector

Install

$ npm i @fibjs/detect-port --save

Usage

const detectPort = require('@fibjs/detect-port');
const availablePort = detectPort();

or

const detectPort = require('@fibjs/detect-port');
const port = 3000;
const availablePort = detectPort(port);
if (availablePort === port) {
  console.log(`port ${port} is available!`);
} else {
  console.log(`port ${port} is not available! Got a random available port: ${availablePort} for you.`);
}

Questions & Suggestions

Please open an issue here.

License

MIT

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free