port-fallback

Start a server on an available port

Usage no npm install needed!

<script type="module">
  import portFallback from 'https://cdn.skypack.dev/port-fallback';
</script>

README

port-fallback

Start a server on an available port. Tries a random higher port if the requested port is taken.

NPM version Build Status

Getting Started

var portFallback = require('port-fallback'),
    http = require('http'),
    defaultPort = 4000,
    server = http.createServer()

portFallback.listen(server,
  {defaultPort: defaultPort},
  function(err, port) {
    console.log("Listening on "+port)
    // ...
  }
)