Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

check in node whether the port is working or not

const net = require("net");
const Socket = net.Socket;

const getNextPort = async (port) => {
    return new Promise((resolve, reject) => {
        const socket = new Socket();

        const timeout = () => {
            resolve(port);
            socket.destroy();
        };

        const next = () => {
            socket.destroy();
            resolve(getNextPort(++port));
        };

        setTimeout(timeout, 200);
        socket.on("timeout", timeout);

        socket.on("connect", function () {
            next();
        });

        socket.on("error", function (exception) {
            if (exception.code !== "ECONNREFUSED") {
                reject(exception);
            } else {
                next();
            }
        });

        socket.connect(port, "0.0.0.0");
    });
};

getNextPort(8080).then(port => {
    console.log("port", port);
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to write a json in r 
Javascript :: how to kill all node processes 
Javascript :: vue custom events 
Javascript :: jquery select the 3rd row of a table 
Javascript :: react native picker 
Javascript :: jquery with npm in laravel 
Javascript :: dynamic navigation with subitems 
Javascript :: react alert popup 
Javascript :: javascript window 
Javascript :: hypot javascript 
Javascript :: Uncaught TypeError: _firebase__WEBPACK_IMPORTED_MODULE_0__.storage.ref is not a function 
Javascript :: jquery onclick anchor tag scroll to div with exact position 
Javascript :: match city regex 
Javascript :: Check for a Null or Empty String in JavaScript 
Javascript :: min heap javascript 
Javascript :: state hook is not updating react 
Javascript :: remove comma from end of string javascript 
Javascript :: console javascript 
Javascript :: how to add element in arry in js 
Javascript :: json full form 
Javascript :: text filed press enter event jquery 
Javascript :: jszip create zip file 
Javascript :: mongoose db connect 
Javascript :: overflow scroll react native 
Javascript :: bodyparser express deprecated 
Javascript :: axios get method 
Javascript :: javascript check if array is subset of another 
Javascript :: js connect to websocket 
Javascript :: Error: contextBridge API can only be used when contextIsolation is enabled 
Javascript :: angular how to check a radiobox 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =