# detect-port-alt

> detect available port

Latest version **1.1.6** (published 2018-04-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install detect-port-alt
pnpm add detect-port-alt
yarn add detect-port-alt
bun add detect-port-alt
```

Provides the commands `detect`, `detect-port`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.6 |
| Published | 2018-04-03 |
| First published | 2017-06-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 4.2.1 |
| Dependencies | 2 |
| Unpacked size | 30.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 392 |
| Maintainers | gaearon, timer |
| Keywords | detect, port |

## Links

- npm: https://www.npmjs.com/package/detect-port-alt
- Repository: https://github.com/node-modules/detect-port
- Issues: https://github.com/node-modules/detect-port/issues
- npm.io page: https://npm.io/package/detect-port-alt

## Dependencies (2)

- [debug](https://npm.io/package/debug.md) ^2.6.0
- [address](https://npm.io/package/address.md) ^1.0.1

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 1.1.6 (latest) — 2018-04-03
- 1.1.5 — 2018-01-14
- 1.1.4 — 2018-01-14
- 1.1.3 — 2017-06-06

## README

[![logo][logo-image]][logo-url]

---

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]

[logo-image]: ./logo.png
[logo-url]: https://npmjs.org/package/detect-port
[npm-image]: https://img.shields.io/npm/v/detect-port.svg?style=flat-square
[npm-url]: https://npmjs.org/package/detect-port
[travis-image]: https://img.shields.io/travis/node-modules/detect-port.svg?style=flat-square
[travis-url]: https://travis-ci.org/node-modules/detect-port
[codecov-image]: https://codecov.io/gh/node-modules/detect-port/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/node-modules/detect-port
[download-image]: https://img.shields.io/npm/dm/detect-port.svg?style=flat-square
[download-url]: https://npmjs.org/package/detect-port

> JavaScript Implementation of Port Detector

## Usage

```bash
$ npm i detect-port --save
```

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

/**
 * callback usage
 */

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}`);
  }
});

/**
 * for a yield syntax instead of callback function implement
 */

const co = require('co');

co(function *() {
  const _port = yield detect(port);

  if (port == _port) {
    console.log(`port: ${port} was not occupied`);
  } else {
    console.log(`port: ${port} was occupied, try port: ${_port}`);
  }
});

/**
 * use as a promise
 */

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);
  });

```

## Command Line Tool

```shell
$ npm i detect-port -g
```

### Quick Start

```shell
# get an available port randomly
$ detect

# detect pointed port
$ detect 80

# more help
$ detect --help
```

## Authors

- [xudafeng](//github.com/xudafeng)
- [zenzhu](//github.com/zenzhu)

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/detect-port-alt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
