Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

detect-port-alt

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

detect-port-alt

detect available port

  • 1.1.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.3M
decreased by-12.79%
Maintainers
2
Weekly downloads
 
Created

What is detect-port-alt?

The detect-port-alt npm package is a utility that helps in checking if a port is already in use and if so, it can suggest an alternative port that is free. This is particularly useful in network programming and development environments where handling port conflicts efficiently is crucial.

What are detect-port-alt's main functionalities?

Check if a port is in use

This feature allows you to check if a specific port (e.g., 3000) is available. If the port is occupied, it suggests another free port.

const detectPort = require('detect-port-alt');

detectPort(3000, (err, port) => {
  if (err) {
    console.error(err);
  } else if (port === 3000) {
    console.log('Port 3000 is available');
  } else {
    console.log('Port 3000 is occupied. Try port:', port);
  }
});

Promise-based port detection

This feature provides a promise-based API to check for port availability, making it easier to integrate with modern JavaScript applications using async/await.

const detectPort = require('detect-port-alt');

async function getAvailablePort(startingPort) {
  try {
    const port = await detectPort(startingPort);
    console.log(`Port ${port} is available`);
    return port;
  } catch (error) {
    console.error('Error:', error);
  }
}

getAvailablePort(3000);

Other packages similar to detect-port-alt

Keywords

FAQs

Package last updated on 03 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc