@finastrides/net-utils
v1.0.0
Published
Network utilities for Node.js
Maintainers
Readme
net-utils
Network utilities for Node.js
Installation
npm install net-utilsUsage
const NetworkUtils = require('net-utils');
const netUtils = new NetworkUtils();
// Fetch with automatic retries
netUtils.fetchWithRetry('https://api.example.com/data')
.then(response => console.log(response.data))
.catch(error => console.error(error));
// Simple fetch
netUtils.fetch('https://example.com')
.then(response => console.log(response.status));
// Ping a host
netUtils.ping('google.com', 443)
.then(latency => console.log(`Latency: ${latency}ms`));
// Get local IP addresses
const ips = netUtils.getLocalIP();
console.log('Local IPs:', ips);
// Validate IP address
const isValid = netUtils.validateIP('192.168.1.1');
console.log('Valid IP:', isValid);
// Parse URL
const parsed = netUtils.parseURL('https://example.com:8080/path?query=1');
console.log(parsed);Configuration
You can customize the default configuration:
const NetworkUtils = require('net-utils');
const netUtils = new NetworkUtils({
timeout: 10000,
retries: 5,
retryDelay: 2000
});API
fetchWithRetry(url, options, retryCount)
Fetch with automatic retry logic
fetch(url, options)
Simple HTTP/HTTPS fetch
ping(host, port)
Ping a host and return latency in milliseconds
getLocalIP()
Get all local IPv4 addresses
validateIP(ip)
Validate an IPv4 address
parseURL(url)
Parse a URL into its components
License
ISC
