Skip to content

Node.js module to detect available ports of the system.

License

Notifications You must be signed in to change notification settings

node-modules/detect-port

Folders and files

NameName
Last commit message
Last commit date

Latest commit

5e71b75 · Dec 11, 2024

History

90 Commits
Dec 8, 2024
Dec 10, 2024
Dec 11, 2024
Jan 17, 2017
Dec 8, 2024
Dec 8, 2024
Dec 10, 2024
Dec 8, 2024
May 16, 2018
Dec 10, 2024
Dec 10, 2024
Dec 8, 2024

Repository files navigation

detect-port

NPM version CI Test coverage Known Vulnerabilities npm download Node.js Version

Node.js implementation of port detector

Who are using or has used

For more

Usage

npm i detect-port

CommonJS

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

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

ESM and TypeScript

import { detect } from 'detect-port';

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

Command Line Tool

npm i detect-port -g

Quick Start

# get an available port randomly
$ detect

# detect pointed port
$ detect 80

# output verbose log
$ detect --verbose

# more help
$ detect --help

FAQ

Most likely network error, check that your /etc/hosts and make sure the content below:

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

License

MIT

Contributors

Contributors

Made with contributors-img.