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

detect-port

Package Overview
Dependencies
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

detect-port

Node.js implementation of port detector

  • 1.6.1
  • latest
  • release-1.x
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.1M
decreased by-19.99%
Maintainers
3
Weekly downloads
 
Created

What is detect-port?

The detect-port npm package is a utility for detecting available network ports on a machine. It is useful for scenarios where you need to find an open port to start a server or service.

What are detect-port's main functionalities?

Detecting an available port

This feature allows you to check if a specific port is available. If the port is occupied, it suggests an alternative available port.

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

const port = 3000;
detect(port, (err, _port) => {
  if (err) {
    console.log(err);
  }
  if (port === _port) {
    console.log(`port ${port} was not occupied`);
  } else {
    console.log(`port ${port} was occupied, try port ${_port}`);
  }
});

Promise-based port detection

This feature provides a promise-based approach to detect an available port, making it easier to integrate with modern JavaScript code that uses async/await.

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

const port = 3000;
detect(port).then(_port => {
  if (port === _port) {
    console.log(`port ${port} was not occupied`);
  } else {
    console.log(`port ${port} was occupied, try port ${_port}`);
  }
}).catch(err => {
  console.log(err);
});

Other packages similar to detect-port

Keywords

FAQs

Package last updated on 08 May 2024

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