JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 15
  • Score
    100M100P100Q43434F

get an available port and preventing eaddrinuse error.

Package Exports

  • fallback-port

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fallback-port) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

fallback-port

get an available port and preventing eaddrinuse error.

Build Status codecov npm version

If multiple applications running same port then you will get the below error (Error: listen EADDRINUSE).

This module will give you an available port and kill other processes.

This module covered Mac OSX and Windows.

Install

$ npm install fallback-port

API

getPid

Finding the PID from default port.

return pid number or null.

getPort

Tries return a random available port if the requested port is taken

kill

Find and kill process locking port.

Example

var port = 8080;

var fallbackPort = new FallbackPort(8080);

//return pid number or null
var pid = fallbackPort.getPid();

//return available port
var otherPort = fallbackPort.getPort();

if(otherPort != port){
    console.log( `${port} is taken` )
}

//kill process
fallbackPort.kill();