# unique-port

> Guarantees your server runs on a unique port

Latest version **1.1.1** (published 2019-04-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install unique-port
pnpm add unique-port
yarn add unique-port
bun add unique-port
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2019-04-18 |
| First published | 2019-04-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Wisdom Ogwu |
| Maintainers | iammadab |
| Keywords | port, node-port, express-port, unique-port, uniq-port |

## Links

- npm: https://www.npmjs.com/package/unique-port
- npm.io page: https://npm.io/package/unique-port

## 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
- [@oxyhq/services](https://npm.io/package/@oxyhq/services.md) — 2.3K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2019-04-18
- 1.1.0 — 2019-04-17
- 1.0.3 — 2019-04-17
- 1.0.2 — 2019-04-14
- 1.0.1 — 2019-04-14
- 1.0.0 — 2019-04-06

## README

# unique-port
Build robust servers by guaranteeing they always run on a unique port

Write your application once, and be sure it always finds a port to run on

Github: https://github.com/iammadab/unique-port

Npm: https://www.npmjs.com/package/unique-port

## Installation

```javascript
    npm install unique-port --save
```

## API

#### with node http server...

```javascript
    const uniquePort = require("unique-port")
    const server = require("http").createServer()

    // Run the server on a unique port
    uniquePort(server)

```

#### or with express...

```javascript
    const uniquePort = require("unique-port")
    const app = require("express")()

    uniquePort(app)
```

### Defaults

By default, unique port tires to serve your application at port 3000.

If it fails, its moves by 1. To 3001 and so on.

#### Default port : 3000
#### Default step : 1

### Want to change the default port?

#### uniquePort(server, port)

```javascript
    const uniquePort = require("unique-port")
    const server = require("express")()

    // Start from port 4000
    uniquePort(server, 4000)
```

### Want to change the step?

#### uniquePort(server, port, step)
    
```javascript
    const uniquePort = require("unique-port")
    const server = require("express")()

    // Start the server from 4000 and step by 100
    uniquePort(server, 4000, 100)
```

This tries to run the server from port 4000 but then steps by 100

So it tries 4000, then 4100 and so on until one is found


### Author
Wisdom Ogwu (iammadab)

[Twitter](https://twitter.com/iammadab)

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