A ultra-lightweight, zero-dependency Node.js utility to quickly find your machine's local IPv4 and IPv6 addresses.
- Zero Dependencies: No bloated
node_modules. - Modern Node Support: Fully compatible with Node.js 18, 20, 22+ (handles both string and numeric
familytypes). - Clean Output: Filters out internal loopback addresses (127.0.0.1) automatically.
- Cross-Platform: Works on Windows, macOS, and Linux.
npm install get-device-ip
π Usage
You can now use this package in any Node.js project without extra configuration.
Modern (ES Modules)
import { getDeviceIP } from 'get-device-ip';
const ip = getDeviceIP();
console.log('Primary IPv4:', ip.primaryIpv4);
console.log('All IPv4s:', ip.IPv4);
Legacy (CommonJS)
const { getDeviceIP } = require('get-device-ip');
const ip = getDeviceIP();
console.log('Primary IPv4:', ip.primaryIpv4);
π Return Object Structure
{
IPv4: [ '192.168.0.100', '172.23.160.1' ],
IPv6: [ 'fe80::2ecc:c31a:a1fc:dcf0' ],
primaryIpv4: '192.168.0.100',
primaryIpv6: 'fe80::2ecc:c31a:a1fc:dcf0'
}
π License MIT Β© Sakib Fakir