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-graphdbVerified import paths — ran on the pinned version, not inferred.
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.
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).
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.
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.
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.
Ensure you are using a named import: `import { Graph } from 'simple-graphdb';` in an ES module environment or with appropriate transpilation.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.
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).No dependency data recorded yet.