Registry / database / memory-level

memory-level

JSON →
library3.1.0jsnpmunverified

memory-level is an in-memory database implementation that adheres to the `abstract-level` API specification, designed for both Node.js and browser environments. It is currently at version 3.1.0 and is actively maintained, with releases often coinciding with upgrades to its underlying `abstract-level` interface. This package serves as the modern successor to earlier in-memory Level implementations like `memdown` and `level-mem`. A key differentiator is its backing by a fully persistent red-black tree, providing reliable in-memory data storage that supports implicit and explicit snapshots. Unlike disk-backed databases, closing or reopening a `memory-level` instance does not affect its stored data, which is only discarded when all references to the database are released. It offers flexible `storeEncoding` options to optimize for Buffer, Uint8Array, or UTF8 string storage, impacting how data types are handled internally for consistency and performance.

npm install memory-level
INSTALL
IMPORT
SIG · MEMORY-LEVEL
M
memory-level
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.

MemoryLevel
import { MemoryLevel } from 'memory-level'
import MemoryLevel from 'memory-level'
MemoryLevel is a named export. Attempting to import it as a default export (without curly braces) will result in an error. The package ships TypeScript types.
MemoryLevel
const { MemoryLevel } = require('memory-level')
const MemoryLevel = require('memory-level')
For CommonJS, MemoryLevel is a named export from the module object. Directly requiring the module and expecting the class to be the default export will fail.
MemoryLevelOptions
import type { MemoryLevelOptions } from 'memory-level'
Type import for configuration options when using TypeScript.

Demonstrates initializing an in-memory `MemoryLevel` database, performing basic `put`, `batch`, `get`, and `iterator` operations, and closing the database.

import { MemoryLevel } from 'memory-level' async function runDbExample() { // Create a database with JSON value encoding const db = new MemoryLevel({ valueEncoding: 'json' }) // Add an entry with key 'a' and value 1 await db.put('a', 1) // Add multiple entries using a batch operation await db.batch([{ type: 'put', key: 'b', value: 2 }]) // Get value of key 'a': 1 const valueA = await db.get('a') console.log('Value of key "a":', valueA) // Expected: 1 // Iterate entries with keys that are greater than 'a' console.log('Entries greater than "a":') for await (const [key, value] of db.iterator({ gt: 'a' })) { console.log('Key:', key, 'Value:', value) // Expected: Key: b Value: 2 } // Clean up resources (optional for in-memory, but good practice) await db.close() } runDbExample().catch(console.error);
Debug
Known issues
breaking`memory-level` v3.0.0 upgraded to `abstract-level` v3, introducing breaking changes to the `abstract-level` API. Consult the `abstract-level` migration guide.
fix
Review the `abstract-level` v3 migration guide for updated API signatures and behaviors. Update your database operations accordingly.
affects: >=3.0.0
breaking`memory-level` v2.0.0 upgraded to `abstract-level` v2, bringing breaking changes to the `abstract-level` API.
fix
Refer to the `abstract-level` v2 migration guide for necessary changes in your application's database interactions.
affects: >=2.0.0 <3.0.0
breaking`memory-level` v2.0.0 dropped support for Node.js versions older than 18. Running on unsupported Node.js versions may lead to unexpected behavior or errors.
fix
Upgrade your Node.js environment to version 18 or newer to ensure compatibility and stability.
affects: >=2.0.0
gotchaWhen storing Buffer values, `memory-level` does not copy the Buffer data. Subsequent mutations to the original Buffer object will directly affect the data stored in the database.
fix
If immutability is required for Buffer values, explicitly clone the Buffer before storing it (e.g., `db.put(key, Buffer.from(myBuffer))`).
affects: >=1.0.0
gotchaThe `createIfMissing` and `errorIfExists` options, common in disk-backed `abstract-level` implementations, are not relevant for `memory-level` and will have no effect.
fix
These options can be safely omitted or ignored when creating a `MemoryLevel` instance, as the in-memory nature makes them superfluous.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: MemoryLevel is not a constructor
Attempting to import MemoryLevel as a default export in ESM (e.g., `import MemoryLevel from 'memory-level'`) or incorrectly requiring in CommonJS (e.g., `const MemoryLevel = require('memory-level')`).
fix
Use named imports for ESM: `import { MemoryLevel } from 'memory-level'`. For CommonJS, use destructuring: `const { MemoryLevel } = require('memory-level')`.
Error [ERR_REQUIRE_ESM]: require() of ES Module .../memory-level/index.js from ... not supported.
Attempting to `require()` memory-level in a CommonJS context when Node.js treats the package as an ES module, or vice-versa with `import` in a CommonJS file. This often occurs in mixed module environments.
fix
Ensure your project's module configuration (`package.json` `type` field or file extensions like `.mjs`/`.cjs`) aligns with how you are importing `memory-level`. For newer projects, consider using ESM throughout. If forced to mix, ensure correct imports for each module system. If using TypeScript, check `tsconfig.json`'s `moduleResolution` and `module` settings.
db.get().on is not a function (or similar error on async methods)
Using older `abstract-level` callback/event-based patterns (e.g., from `leveldown` or `levelup`) with `memory-level` versions that have upgraded to a Promise-based `abstract-level` API (v2+).
fix
Update your code to use the modern Promise-based `async/await` syntax for `get`, `put`, `del`, `batch`, and `iterator` operations as demonstrated in the quickstart, in line with `abstract-level` v2 and v3.
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies
abstract-levelrequiredCore API interface that memory-level implements. Understanding abstract-level's API is crucial for using memory-level.
functional-red-black-treerequiredUnderlying data structure used for efficient in-memory storage.
Agent activity
6 hits · last 30 days
node
6
Resources
memory-level — npm install memory-level · libregistry