1.1.1 • Published 5 years ago

unique-port v1.1.1

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

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

    npm install unique-port --save

API

with node http server...

    const uniquePort = require("unique-port")
    const server = require("http").createServer()

    // Run the server on a unique port
    uniquePort(server)

or with express...

    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)

    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)

    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

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago