npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

network-default-gateway

v1.2.3

Published

Effortlessly discover machine's default gateway with zero external dependency

Readme

network-default-gateway

CI

Purpose

Effortlessly discover machine's default gateway with zero external dependency. This package provides the IP address, gateway, interface name, and prefix length, automatically detecting the runtime environment and platform.

It includes runtime-specific code for Bun, Deno, and Node, along with OS-specific code. Both types of code are only loaded when necessary, ensuring minimal impact on performance.

How it works

This package retrieves the default gateway by spawning OS-level commands, which are available by default on each system and require no additional installation. Specifically:

  • Linux: ip
  • macOS: route and ifconfig
  • Windows: PowerShell’s Get-NetRoute and Get-NetIPAddress

The commands are spawned through the active runtime. Specifically:

  • Bun: Bun.spawn
  • Deno: Deno.Command
  • Node: spawn from child_process

The output of these commands is parsed into JSON (on Linux and Windows) or processed using grep and awk (on macOS), ensuring a consistent key–value structure for all retrieved information.

It is ESM-only and fully written in TypeScript. It is available on JSR and npm.

Works on

The package has been tested and works correctly on the following operating systems and runtimes:

| | Bun | Deno | Node | |-------------|------|------|------| | macOS | ✔ | ✔ | ✔ | | Linux | ✔ | ✔ | ✔ | | Windows | ✔ | ✔ | ✔ |

JSR

For complete installation and usage details with JSR, visit the package page.

From JSR, you can install the package and access documentation for all available methods. It is recommended for use with Bun and Deno, with sources available directly in TypeScript.

npm

Installation:

npm install network-default-gateway

IPv4 import:

import { v4DefaultGateway } from 'network-default-gateway';

IPv6 import:

import { v6DefaultGateway } from 'network-default-gateway';

Usage example

IPv4:

(async () => {
  // Get default gateway details for IPv4 address
  const defaultGateway = await v4DefaultGateway();
  console.log(defaultGateway);
  /*
  {
    ip: '192.168.1.15',
    gateway: '192.168.1.1',
    interface: 'eth1',
    prefixLength: 24
  }
  */
})();

IPv6:

(async () => {
  // Get default gateway details for IPv6 address
  const defaultGateway = await v6DefaultGateway();
  console.log(defaultGateway);
  /*
  {
    ip: 'fe80::1a2b:3c4d:5e6f:7g8h',
    gateway: 'fe80::1',
    interface: 'eth1',
    prefixLength: 64
  }
  */
})();

Test

Bun:

bun test test/bun.test.ts

Deno:

deno test test/deno.test.ts --allow-run

Node:

npm install
npm run test

Contribute

I'm happy to welcome any contribution, big or small, feel free to contribute however you prefer! Whether it's code or just suggestions, everything is appreciated. Please use the GitHub Discussions section to share your ideas or ask questions.

This package is being developed to replace default-gateway package, which has been marked by the creator with "Intention to deprecate this module". We encourage contributions to help us achieve this ambitious goal.

License

network-default-gateway is MIT licensed.