The `network-interfaces` package provides synchronous utility functions for retrieving and filtering network interface and IP address information in Node.js. It acts as a wrapper around Node.js's built-in `os.networkInterfaces()` method, offering simplified functions like `toIp`, `toIps`, `fromIp`, `getInterface`, and `getInterfaces` with optional filtering by internal status and IP version (IPv4/IPv6). The current stable version is 1.1.0, last published in 2017. Due to its age and lack of maintenance, it is considered abandoned. Users are encouraged to directly use `os.networkInterfaces()` or seek more actively maintained alternatives for robust network interface management in modern Node.js applications, especially if TypeScript support or ESM compatibility is required.
npm install network-interfacesVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `network-interfaces` to find external IPv4 interface names, retrieve an IP address for a given interface, and determine an interface name from a specific IP address, including error handling.
Migrate to `os.networkInterfaces()` for core functionality or consider an actively maintained alternative. Ensure thorough testing on your target Node.js version.
Always wrap calls to potentially failing functions in `try...catch` blocks: `try { const ip = ni.toIp('nonexistent'); } catch (e) { console.error(e.message); }`Install `@types/network-interfaces` (`npm install --save-dev @types/network-interfaces`) or define custom types if the `@types` package is outdated. For new projects, consider libraries with native TypeScript support.
Carefully define your `options` object based on whether you need internal/external interfaces or specific IP versions. If both are needed, omit the respective filter property.
Verify the interface name and ensure your filtering options (e.g., `ipVersion: 4`, `internal: false`) correctly match available addresses. Use `ni.getInterfaces()` to list existing interfaces with their properties.
Confirm the IP address is active and correctly configured on one of the system's network interfaces. Adjust filtering options if they are too restrictive.
Ensure you are using `const ni = require('network-interfaces');` in CommonJS modules (`.js` files without `"type": "module"` in `package.json` or `.cjs` files). If using ESM, be aware of the package's age and potential lack of native ESM support; a bundler might be needed or consider `import * as ni from 'network-interfaces';` as a fallback, though direct `os.networkInterfaces` is preferred for modern projects.No dependency data recorded yet.