Registry / database / simple-graphdb

simple-graphdb

JSON →
library3.1.0jsnpmunverified

Simple-graphdb is an open-source, lightweight, in-memory graph database designed for managing graph data structures directly within a JavaScript/TypeScript application. Currently at version 3.1.0, it offers a stable API for creating, manipulating, and traversing nodes and edges with properties. Unlike persistent graph databases such as Neo4j or Ontotext's GraphDB, simple-graphdb does not offer data persistence or advanced enterprise features like clustering or complex query languages. Its primary differentiators are its simplicity, zero-dependency footprint, and suitability for use cases where graph data needs to be modeled and queried programmatically within a single application process, such as social network simulations, routing algorithms, or in-memory knowledge graphs for smaller datasets. The library typically follows a moderate, stable release cadence, focusing on core graph operations and performance within its in-memory scope.

npm install simple-graphdb
INSTALL
IMPORT
SIG · SIMPLE-GRAPHDB
S
simple-graphdb
databasejavascriptv3.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Graph
import { Graph } from 'simple-graphdb';
const Graph = require('simple-graphdb');
The primary class for creating and interacting with a graph. Use named import for ESM environments.
Node
import { Node } from 'simple-graphdb';
Type definition for a graph node. Primarily used for TypeScript type hinting.
Edge
import { Edge } from 'simple-graphdb';
Type definition for a graph edge/relationship. Primarily used for TypeScript type hinting.

This quickstart demonstrates how to initialize a graph, add nodes and edges with properties, and perform basic traversal and querying operations to find related data.

import { Graph } from 'simple-graphdb'; // Create a new graph instance const graph = new Graph(); // Add nodes with types and properties const userNode = graph.addNode('User', { name: 'Alice', email: 'alice@example.com' }); const productNode = graph.addNode('Product', { name: 'Laptop', price: 1200 }); const orderNode = graph.addNode('Order', { orderId: 'ORD001', date: new Date() }); // Add directed edges to represent relationships graph.addEdge(userNode.id, orderNode.id, 'PLACED'); graph.addEdge(orderNode.id, productNode.id, 'CONTAINS', { quantity: 1 }); // Query the graph const aliceOrders = graph.getChildren(userNode.id, { edgeType: 'PLACED' }); console.log('Alice\'s orders:', aliceOrders.map(node => node.properties)); const orderProducts = graph.getChildren(orderNode.id, { edgeType: 'CONTAINS' }); console.log('Products in Order ORD001:', orderProducts.map(node => node.properties)); // Find a path between Alice and the Laptop product const path = graph.traverse(userNode.id, productNode.id, { method: 'bfs' }); if (path) { console.log('Path from Alice to Laptop:', path); } else { console.log('No path found from Alice to Laptop.'); }
Debug
Known issues
gotchasimple-graphdb is an in-memory database. All data is lost when the application process terminates unless explicitly serialized and deserialized by the user. There are no built-in persistence mechanisms.
fix
Implement custom serialization (e.g., to JSON) and deserialization logic to save and load graph state. For example: `const data = graph.toJSON(); // Save data... const loadedGraph = Graph.fromJSON(data);` (Check API for exact serialization methods).
affects: >=1.0.0
gotchaPerformance may degrade significantly with very large graphs (tens of thousands of nodes/edges or more) due to its in-memory nature and single-threaded JavaScript execution. It is not designed for petabyte-scale graph data.
fix
For very large datasets or complex analytical queries, consider migrating to a dedicated, persistent graph database (e.g., Neo4j, Apache TinkerPop, JanusGraph) or optimizing your graph structure and queries.
affects: >=1.0.0
gotchaNode and edge IDs are internally generated strings. While unique within a single graph instance, they are not guaranteed to be stable across application restarts or different graph instances unless you manage them explicitly during serialization/deserialization.
fix
When serializing and deserializing, ensure that the ID mapping is preserved, or design your application to handle potentially new IDs upon reload, identifying nodes by their unique properties if IDs are not stable.
affects: >=1.0.0
gotchaThe library does not provide built-in concurrency control or transaction management. If multiple asynchronous operations modify the same graph instance concurrently, data corruption or unexpected behavior may occur.
fix
Ensure all graph modifications are synchronized or performed in a single-threaded context. If using in a multi-threaded (e.g., Worker threads) or highly concurrent async environment, implement your own locking or queueing mechanism for graph access.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Graph is not a constructor
Attempting to import the Graph class incorrectly, often using a default import or CommonJS `require()` pattern instead of a named import for an ESM-style module.
fix
Ensure you are using a named import: `import { Graph } from 'simple-graphdb';` in an ES module environment or with appropriate transpilation.
Error: Node with ID 'xyz123' not found.
Attempting to access, modify, or traverse from a node ID that does not exist in the current graph instance.
fix
Verify the node ID exists using `graph.hasNode(id)` before attempting operations, or ensure that the ID is correctly obtained from a previously added node or a deserialized graph.
Cannot find module 'simple-graphdb'
Node.js (or bundler) cannot resolve the package, often due to an ES module/CommonJS mismatch or incorrect `tsconfig.json`/`package.json` configuration.
fix
Ensure your project is configured for ES Modules (e.g., `"type": "module"` in `package.json`, targetting `esnext` in `tsconfig.json`), or verify that your bundler (Webpack, Rollup, etc.) is correctly configured to handle ES Modules. If using CommonJS, ensure you're using `const { Graph } = require('simple-graphdb');` (though this might not work if the package is strictly ESM).
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
1
Resources