{"id":16312,"library":"classic-level","title":"Classic LevelDB Database","description":"classic-level is an `abstract-level` compliant database implementation backed by LevelDB, serving as the successor to `leveldown`. It offers features such as built-in encodings, sublevels, events, hooks, and first-class support for `Uint8Array`. The current stable version is 3.0.0, with a release cadence that has seen several minor and major updates in the past year, indicating active maintenance. Key differentiators include its adherence to the `abstract-level` interface, providing a consistent API across various Level-family databases, and its direct use of the battle-tested LevelDB C++ library for high performance. It also ships with TypeScript type definitions, making it suitable for modern JavaScript and TypeScript projects. It supports Node.js versions >=18 and Electron >=30, providing prebuilt binaries for common platforms.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/Level/classic-level","tags":["javascript","leveldb","level","typescript"],"install":[{"cmd":"npm install classic-level","lang":"bash","label":"npm"},{"cmd":"yarn add classic-level","lang":"bash","label":"yarn"},{"cmd":"pnpm add classic-level","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"classic-level implements the abstract-level API and relies on it for core functionality and interface definition.","package":"abstract-level","optional":false}],"imports":[{"note":"While CommonJS `require` still works for basic usage, prefer ESM `import` in modern Node.js environments (>=18).","wrong":"const ClassicLevel = require('classic-level')","symbol":"ClassicLevel","correct":"import { ClassicLevel } from 'classic-level'"},{"note":"This is the CommonJS `require` syntax as shown in the package's README example for Node.js. It's a named export, not a default export.","wrong":"import ClassicLevel from 'classic-level'","symbol":"ClassicLevel","correct":"const { ClassicLevel } = require('classic-level')"},{"note":"TypeScript types are shipped with the package and can be imported directly from the main package entrypoint.","wrong":"import { ClassicLevel } from 'classic-level/types'","symbol":"ClassicLevel","correct":"import type { ClassicLevel } from 'classic-level'"}],"quickstart":{"code":"import { ClassicLevel } from 'classic-level';\nimport { rmSync } from 'node:fs';\n\nconst dbPath = './my-classic-level-db';\n\nasync function runExample() {\n  // Clean up previous run if any\n  try { rmSync(dbPath, { recursive: true, force: true }); } catch (e) {}\n\n  // Create a database instance with JSON value encoding\n  const db = new ClassicLevel(dbPath, { valueEncoding: 'json' });\n\n  try {\n    // Open the database\n    await db.open();\n    console.log('Database opened.');\n\n    // Add a single entry\n    await db.put('user:1', { name: 'Alice', age: 30 });\n    console.log('Added user:1');\n\n    // Add multiple entries using batch operation\n    await db.batch([\n      { type: 'put', key: 'user:2', value: { name: 'Bob', age: 25 } },\n      { type: 'put', key: 'user:3', value: { name: 'Charlie', age: 35 } }\n    ]);\n    console.log('Added user:2 and user:3 via batch');\n\n    // Retrieve a value\n    const user1 = await db.get('user:1');\n    console.log('Retrieved user:1:', user1);\n\n    // Iterate over entries with keys greater than 'user:1'\n    console.log('Iterating users > user:1:');\n    for await (const [key, value] of db.iterator({ gt: 'user:1' })) {\n      console.log(`  Key: ${key}, Value:`, value);\n    }\n\n  } catch (error) {\n    console.error('An error occurred:', error);\n  } finally {\n    // Close the database\n    await db.close();\n    console.log('Database closed.');\n  }\n}\n\nrunExample();\n","lang":"typescript","description":"This example demonstrates how to initialize a `ClassicLevel` database, perform basic `put`, `batch`, `get`, and `iterator` operations, and handle database opening and closing. It uses ESM syntax and includes a cleanup step for repeated execution."},"warnings":[{"fix":"Consult the `UPGRADING.md` guide in the classic-level repository for detailed instructions and potential breaking changes in `abstract-level` v3. Review your database operations and ensure compatibility with the new abstract-level API.","message":"Version 3.0.0 introduced a breaking change by upgrading to `abstract-level` v3. This might require updating your code if you are interacting directly with `abstract-level`'s low-level API or specific features that changed.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Migrate all database operations to use Promises (e.g., `await db.get(...)`). Handle 'not found' cases by catching the `LevelNotFoundError` (or similar error type, depending on `abstract-level` version) instead of checking for `LEVEL_NOT_FOUND`.","message":"Version 2.0.0 removed traditional callback-style APIs for database operations, favoring Promises. Additionally, the `LEVEL_NOT_FOUND` error constant was removed.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure you have a complete build environment for `node-gyp`, including Python, `make` (or equivalent), and a C/C++ compiler. Refer to the `node-gyp` installation guide. Alternatively, use `npm install classic-level --build-from-source` to explicitly trigger a source build for debugging purposes.","message":"For platforms without prebuilt binaries (e.g., specific architectures or older OS versions), `classic-level` will attempt to compile from source. This requires a valid `node-gyp` installation, which can be a common source of installation issues.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure only one `ClassicLevel` instance attempts to open a database at a given file system location simultaneously. Properly close database instances when they are no longer needed to release the lock. Consider using `db.open()` and `db.close()` within `try...finally` blocks to guarantee cleanup.","message":"Attempting to open a `ClassicLevel` database at a `location` that is already exclusively locked by another process or another `ClassicLevel` instance will result in a `LEVEL_LOCKED` error.","severity":"gotcha","affected_versions":">=1.2.0"},{"fix":"Always review the `UPGRADING.md` document for your target version when upgrading `classic-level` or any related `Level` packages to understand breaking changes, new features, and migration paths.","message":"The `UPGRADING.md` file in the repository contains critical information for migrating between major versions. Neglecting to consult it can lead to unexpected behavior or errors.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure that no other applications or database instances are accessing the same database location. Verify that previous database instances were properly closed. You might need to manually remove the `LOCK` file if a process crashed and left it behind, but do so with caution.","cause":"Another process or `ClassicLevel` instance is currently holding a lock on the database directory, preventing it from being opened.","error":"Error: IO error: While lock file: /path/to/db/LOCK: Resource temporarily unavailable"},{"fix":"Update your code to use the Promise-based API for all database operations. For `db.put`, simply `await db.put(key, value)` without a callback.","cause":"This usually indicates an attempt to use `db.put()` with a callback function, which was removed in v2.0.0.","error":"TypeError: db.put is not a function"},{"fix":"Install the necessary `node-gyp` dependencies, including Python, `make`/`build-essential` (Linux), Xcode Command Line Tools (macOS), or Visual C++ Build Tools (Windows). Refer to the `node-gyp` GitHub page for detailed installation instructions for your OS.","cause":"The package failed to find a prebuilt binary for your platform and is attempting to compile the native LevelDB module, but the `node-gyp` build tools are missing or misconfigured.","error":"Error: N-API library not found, trying to rebuild from source..."}],"ecosystem":"npm"}