Detalhes do pacote

detect-port

node-modules21.5mMIT2.1.0

Node.js implementation of port detector

detect, port

readme (leia-me)

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.

changelog (log de mudanças)

Changelog

2.1.0 (2024-12-10)

Features

  • refactor with async/await instead of callback (#59) (9254c18)

2.0.1 (2024-12-08)

Bug Fixes

2.0.0 (2024-12-08)

⚠ BREAKING CHANGES

  • Drop Node.js < 16 support

  • 使用 ts 重构

  • 使用 tshy 支持 esm 和 cjs
  • test 使用 test-runner (这里需要 node v18 版本)

merge from https://github.com/node-modules/detect-port/pull/51

Summary by CodeRabbit

  • New Features
  • Introduced a new waitPort function to asynchronously wait for a specified port to become available.

    • Added a new ESLint configuration to enforce TypeScript linting rules.
  • Bug Fixes

    • Reverted a feature in the detect-port package due to issues raised.
  • Documentation

    • Updated README.md for improved clarity and updated badge links.
    • Modified CONTRIBUTING.md to reflect changes in testing commands.
  • Chores

    • Introduced a new TypeScript configuration file (tsconfig.json).
  • Updated package.json to reflect changes in dependencies and project structure.

  • Tests

  • Added comprehensive tests for the new waitPort and updated tests for the CLI and detectPort function.

Features

  • refactor with typescript to support esm and cjs both (#56) (b5d32d2)

1.6.1 (2024-05-08)

Reverts

  • Revert "feat: use address@2 (#53)" (#54) (48dfe47), closes #53 #54

1.6.0 (2024-05-08)

Features


1.5.1 / 2022-09-23

fixes

1.5.0 / 2022-09-21

features

fixes

others

1.3.0 / 2018-11-20

features

others

1.2.3 / 2018-05-16

fixes

others

1.1.3 / 2017-05-24

  • fix: should ignore getaddrinfo ENOTFOUND error (#22)

1.1.2 / 2017-05-11

  • fix: should double check 0.0.0.0 and localhost (#20)
  • docs: ignore type of port when checking if it's occupied (#18)

1.1.1 / 2017-03-17

  • fix: try to use next available port (#16)

1.1.0 / 2016-01-17

  • Use server listen to detect port

1.0.7 / 2016-12-11

  • Early return for rejected promise
  • Prevent promsie swallow in callback

1.0.6 / 2016-11-29

  • Bump version for new Repo

0.1.4 / 2015-08-24

  • Support promise

0.1.2 / 2014-05-31

  • Fix commander

0.1.1 / 2014-05-30

  • Add command line support

0.1.0 / 2014-05-29

  • Initial release