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

virtual-net

v1.0.1

Published

Simulate a virtual network with isolated nodes

Readme

VirtualNet

Create virtual network topologies using Linux network namespaces directly from Node.js.

VirtualNet makes it easy to spin up isolated nodes connected through a virtual bridge, simulate network conditions (latency, packet loss, bandwidth limits), and run processes inside each node.

This is useful for distributed systems testing.


Installation

npm install virtual-net

⚠️ Requires Linux with iproute2 and tc. Most commands require sudo/root privileges because network namespaces are used.


Overview

The module creates a simple topology:

graph TD

subgraph HUB["node1 (hub namespace)"]
    br0["Linux Bridge: br0<br/>IP: 10.0.0.1"]
end

subgraph N2["node2 namespace"]
    v2["veth2<br/>10.0.0.2"]
end

subgraph N3["node3 namespace"]
    v3["veth3<br/>10.0.0.3"]
end

subgraph N4["node4 namespace"]
    v4["veth4<br/>10.0.0.4"]
end

br0 ---|"veth1-2"| v2
br0 ---|"veth1-3"| v3
br0 ---|"veth1-4"| v4
  • node1 acts as the hub containing a bridge (br0)
  • All other nodes connect via veth pairs
  • Each node gets an IP in the same subnet

Example IP layout:

node1 -> 10.0.0.1
node2 -> 10.0.0.2
node3 -> 10.0.0.3
node4 -> 10.0.0.4

Quick Example

const { VirtualNet } = require("virtual-net");

async function main() {
  const net = new VirtualNet({ peers: 4 });

  await net.start();

  const node2 = net.node(2);
  const node3 = net.node(3);

  node2.exec("ping -c 3 10.0.0.3");

  // add latency
  net.latency(2, { delay: "100ms" });

  node2.exec("ping 10.0.0.3");

  // cleanup
  net.stop();
}

main();

API

VirtualNet

Constructor

new VirtualNet(options)

Options:

| Option | Default | Description | | -------- | -------- | ------------------------------ | | peers | 5 | Number of nodes in the network | | prefix | 10.0.0 | IP subnet prefix |

Example:

const net = new VirtualNet({
  peers: 3,
  prefix: "10.1.0"
});

start()

Creates the virtual network:

  • deletes old namespaces
  • creates nodes
  • creates bridge
  • connects nodes with veth pairs
  • assigns IP addresses
await net.start();

stop()

Removes all created network namespaces.

net.stop();

node(id)

Returns a Node instance representing a network namespace.

const node2 = net.node(2);

ip(id)

Returns the IP address of a node.

net.ip(3);
// 10.0.0.3

latency(peer, options)

Apply network shaping using tc netem.

Options:

| Option | Example | | ------- | --------- | | delay | "100ms" | | loss | "5%" | | rate | "1mbit" |

Example:

net.latency(2, {
  delay: "200ms",
  loss: "2%",
  rate: "5mbit"
});

clearLatency(peer)

Remove traffic shaping from a node.

net.clearLatency(2);

Node API

Node represents a single network namespace.


spawn(cmd, args, options)

Spawn a process inside the node.

node.spawn("ping", ["10.0.0.3"]);

Equivalent to:

sudo ip netns exec nodeX <cmd>

exec(command)

Execute a shell command.

node.exec("ping -c 3 10.0.0.3");

fork(modulePath, args)

Run a Node.js script inside the node.

node.fork("server.js");

repl()

Open an interactive shell inside the node.

node.repl();

This runs:

sudo ip netns exec nodeX bash

Example: Distributed Node Test

const { VirtualNet } = require("virtualnet");

async function run() {
  const net = new VirtualNet({ peers: 3 });
  await net.start();

  net.node(2).fork("./server.js");
  net.node(3).fork("./client.js", [net.ip(2)]);
}

run();

Requirements

  • Linux
  • iproute2
  • tc
  • sudo access

Install dependencies:

sudo apt install iproute2

Cleanup Tip

If something crashes:

sudo ip netns list
sudo ip netns delete node1

Or just call:

net.stop();

License

MIT