npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

is-port-available

0.1.5 • Public • Published

is-port-available (nodejs)

(async) isPortAvailable() : Will test the requested port, resolving the returned Promise with true, when port IS AVAILABLE, and false when NOT AVAILABLE.

NOTE: When port is NOT AVAILABLE, the fail reason (err.code | err) can be checked reading isPortAvailable.lastError property (wich is reset automatically before each call to isPortAvailable)

Methods

isPortAvailable( port ) (function) => Expects an integer, and returns a Promise that resolves in true|false

isPortAvailable.lastError (string) => Contains the last call error (EADDRINUSE, EACCES...)

Installation

Use npm to install the module : $ npm install --save is-port-available

NPM Package Page

Usage

Example of a simple port avaiability test via Promise.then():

    const isPortAvailable = require('is-port-available');
 
    var port = 80;
    isPortAvailable(port).then( status =>{
        if(status) console.log('Port ' + port + ' IS available!');
        else{
            console.log('Port ' + port + ' IS NOT available!');
            console.log('Reason : ' + isPortAvailable.lastError);
        }
    });

Example Using await inside an async self invoking function :

    const isPortAvailable = require('is-port-available');
 
    (async function(){
        var port = 80;
        var status = await isPortAvailable(port);
 
        if(status) console.log('Port ' + port + ' IS available!');
        else{
            console.log('Port ' + port + ' IS NOT available!');
            console.log('Reason : ' + isPortAvailable.lastError);
        }
 
    })()

Licence

GPL

install

npm i is-port-available

Downloadsweekly downloads

557

version

0.1.5

license

GPL-3.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability