1. endpoint-utils
Utils to deal with TCP ports and hostnames. Safe for everyday use.
endpoint-utils
Package: endpoint-utils
Created by: inikulin
Last modified: Fri, 17 Jun 2022 05:12:33 GMT
Version: 1.0.2
License: MIT
Downloads: 893,723
Repository: https://github.com/inikulin/endpoint-utils

Install

npm install endpoint-utils
yarn add endpoint-utils

endpoint-utils

Build Status

Utils to deal with TCP ports and hostnames. Safe for everyday use.

Install

npm install endpoint-utils

Usage

Get free port

 const getFreePort = require('endpoint-utils').getFreePort;

getFreePort().then(port => {
    console.log(port);
    //> 1337
});

Get multiple free ports

 const getFreePorts = require('endpoint-utils').getFreePorts;

getFreePorts(3).then(ports => {
    console.log(ports);
    //> [1337, 1338, 1339]
});

Check if port is free

 const isFreePort = require('endpoint-utils').isFreePort;

isFreePort(1337).then(isFree => {
    console.log(isFree);
    //> true
});

Check if hostname or IP address resolves to the current machine

 const isMyHostname = require('endpoint-utils').isMyHostname;

isMyHostname('inikulin').then(isMy => {
    console.log(isMy);
    //> true
});

isMyHostname('172.22.5.80').then(isMy => {
    console.log(isMy);
    //> true
});

Get hostname or IP address which can be resolved to the current machine

 const getMyHostname = require('endpoint-utils').getMyHostname;

getMyHostname().then(hostname => {
    console.log(hostname);
    //> "inikulin.local"
});

Get IP address of current machine

 const getIPAddress = require('endpoint-utils').getIPAddress;

console.log(getIPAddress());
//> "172.22.5.80"

Author

Ivan Nikulin ([email protected])

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code