{"id":18311,"library":"enmap","title":"Enmap","description":"Enmap is a synchronous, persistent key-value store built on better-sqlite3, designed as a drop-in replacement for JavaScript's Map with additional array methods. Current stable version is 6.1.6, requiring Node >=20. It is TypeScript-compatible and anti-ORM, meaning it can store any serializable data without a predefined schema. Unlike typical databases or ORMs, Enmap provides a simple Map-like API with automatic persistence, making it ideal for beginners and rapid prototyping, especially in Discord bot development. It is actively maintained and synchronous, avoiding callbacks and promises.","status":"active","version":"6.1.6","language":"javascript","source_language":"en","source_url":"https://github.com/eslachance/enmap","tags":["javascript","sqlite","sql","sqlite3","better-sqlite3","db","database","caching","storing","typescript"],"install":[{"cmd":"npm install enmap","lang":"bash","label":"npm"},{"cmd":"yarn add enmap","lang":"bash","label":"yarn"},{"cmd":"pnpm add enmap","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"SQLite3 bindings for synchronous database operations","package":"better-sqlite3","optional":false}],"imports":[{"note":"ESM-only package; CommonJS require() is not supported in v6.","wrong":"const Enmap = require('enmap')","symbol":"Enmap","correct":"import Enmap from 'enmap'"},{"note":"Enmap is a default export, not a named export.","wrong":"import { Enmap } from 'enmap'","symbol":"Enmap","correct":"import Enmap from 'enmap'"},{"note":"Options object is passed directly to constructor; no separate type/constant exported.","wrong":"import Enmap, { Options } from 'enmap'","symbol":"Enmap Options","correct":"import Enmap from 'enmap'\nconst enmap = new Enmap({ name: 'myEnmap' })"}],"quickstart":{"code":"import Enmap from 'enmap';\n\nconst enmap = new Enmap({ name: 'myData' });\n\n// Set a value\nenmap.set('key1', { name: 'Alice', score: 100 });\n\n// Get a value\nconst data = enmap.get('key1');\nconsole.log(data);\n\n// Check if key exists\nif (enmap.has('key1')) {\n  console.log('Key exists!');\n}\n\n// Delete a key\nenmap.delete('key1');\n\n// Array methods\nenmap.set('a', 1);\nenmap.set('b', 2);\nconst sum = enmap.reduce((acc, val) => acc + val, 0);\nconsole.log(sum); // 3\n\n// Close the database\nenmap.close();","lang":"typescript","description":"Demonstrates creating an Enmap instance, setting/getting/deleting keys, using reduce method, and closing the database."},"warnings":[{"fix":"Use import syntax (ESM) or downgrade to v5.x for CommonJS support.","message":"Version 6 uses ESM only; CommonJS require() will throw an error.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Upgrade Node.js to >=20 or use Enmap v5.x.","message":"Node.js version 20 or higher is required for v6.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"For large writes, consider batching or using asynchronous alternatives like better-sqlite3 directly.","message":"Enmap stores data synchronously; blocking operations can freeze the event loop on large datasets.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `filter()` or `find()` with caution; prefer `filter()` for multiple matches.","message":"The `find()` method returns the first match, not an array, which differs from Array.prototype.find().","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Ensure values are JSON-serializable; use custom serialization if needed.","message":"Serialization: Objects are stored as JSON, so functions, undefined, and circular references will cause errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Switch to import syntax: import Enmap from 'enmap'. Alternatively, downgrade to v5.x.","cause":"Using CommonJS require() with v6 ESM-only package.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/enmap from /path/to/yourfile.js not supported."},{"fix":"Use import Enmap from 'enmap' (default import) instead of import { Enmap } from 'enmap'.","cause":"Named import instead of default import.","error":"TypeError: Enmap is not a constructor"},{"fix":"Ensure you call new Enmap({ name: 'yourname' }) before any operations.","cause":"Attempting to use an Enmap without first creating/opening it properly.","error":"Error: SQLITE_ERROR: no such table: enmap"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}