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

@hanzifinder-chao/networkxjs

v0.0.2

Published

A JavaScript library for graph data structures and algorithms, inspired by Python's NetworkX.

Readme

🌐 NetworkXJS - A Graph Library for JavaScript

npm version License: MIT

NetworkXJS is a JavaScript library for working with graph data structures and graph algorithms, inspired by Python's NetworkX. It provides an easy-to-use API for building, analyzing, and manipulating graphs in JavaScript.

🚀 Why NetworkXJS?

  • Simple & Flexible: Designed for both beginners and advanced users.
  • Strict Graph Handling: No implicit node creation. Nodes must be explicitly added.
  • Supports Node & Edge Attributes: Store metadata on both nodes and edges.
  • Fast & Lightweight: Uses Map and Set for efficient graph operations.
  • No Dependencies: Works in both Node.js and Browser environments.

📦 Installation

To use NetworkXJS, simply install it via npm or pnpm:

# Using npm
npm install networkxjs

# Using pnpm
pnpm add networkxjs

In browser environments, you can include the library via a CDN:

<script src="/url/to/networkxjs.umd.js"></script>
<script>
  const G = new NetworkXJS.Graph();
  G.addNode(1);
  G.addEdge(1, 2);
  console.log(G.hasEdge(1, 2));  // true
</script>

🚀 Quick Start

1️⃣ Import the library

import { Graph } from 'networkxjs';

// OR (if using CommonJS)
const { Graph } = require('networkxjs');

2️⃣ Create a graph

const G = new Graph();

G.addNode(1, { color: "red" });
G.addNode("A", { color: "blue" });

console.log(G.hasNode(1));  // true
console.log(G.hasNode("B"));  // false

3️⃣ Add edges

G.addEdge(1, "A", { weight: 5 });
console.log(G.hasEdge(1, "A")); // true

// Retrieve edge attributes
console.log(G.edge(1, "A")); // { weight: 5 }

4️⃣ Remove nodes & edges

G.removeEdge(1, "A");
console.log(G.hasEdge(1, "A")); // false

G.removeNode("A");
console.log(G.hasNode("A")); // false

🎯 API Reference

🔹 Graph Methods

| Method | Description | |--------|------------| | addNode(id, attr={}) | Add a node with an optional attribute object. | | addNodesFrom([...]) | Add multiple nodes at once. | | hasNode(id) | Check if a node exists. | | node(id) | Get node attributes (throws if not found). | | removeNode(id) | Remove a node and all connected edges. | | addEdge(u, v, attr={}) | Add an undirected edge (nodes must exist). | | hasEdge(u, v) | Check if an edge exists. | | edge(u, v) | Get edge attributes (throws if not found). | | removeEdge(u, v) | Remove an edge. | | neighbors(id) | Get all neighbors of a node. | | numberOfNodes() | Get the total number of nodes. | | numberOfEdges() | Get the total number of edges. |


🛠 Common Issues & FAQs

❓ Why do I get an error when adding an edge?

NetworkXJS does not auto-create nodes. You must add both nodes before adding an edge.

const G = new Graph();
G.addNode(1);
G.addNode(2);
G.addEdge(1, 2);  // ✅ Works fine

G.addEdge(3, 4);  // ❌ Error: Node "3" does not exist.

❓ Can I use objects as node IDs?

No. Node IDs must be strings or numbers to ensure fast lookups.

❓ Does it support directed graphs?

Not yet. Future versions may include DiGraph.


👥 Contributing

We welcome contributions! To contribute:

  1. Fork the repository on GitHub.
  2. Clone your fork and install dependencies:
    git clone https://github.com/yourusername/networkxjs.git
    cd networkxjs
    pnpm install
  3. Run tests before submitting a PR:
    pnpm test
  4. Submit a pull request 🎉

📜 License

This project is licensed under the MIT License.