Registry / database / keyvaluestorage

keyvaluestorage

JSON →
library0.7.1jsnpmunverified

Isomorphic key-value storage library (v0.7.1) that works across Node.js, React Native, and browser environments. Provides a unified API (setItem, getItem, removeItem, getKeys, getEntries) with different backends: SQLite for Node.js, AsyncStorage for React Native, and localStorage for browsers. Requires explicit adapter configuration per platform, which is a common source of errors. TypeScript types included. Low release cadence; active development.

npm install keyvaluestorage
INSTALL
IMPORT
SIG · KEYVALUESTORAGE
K
keyvaluestorage
databasejavascriptv0.7.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

IKeyValueStorage
import { IKeyValueStorage } from 'keyvaluestorage'
import IKeyValueStorage from 'keyvaluestorage'
IKeyValueStorage is a named export of the interface.
KeyValueStorage
import KeyValueStorage from 'keyvaluestorage'
import { KeyValueStorage } from 'keyvaluestorage'
KeyValueStorage is the default export of the class.
default import
import KeyValueStorage from 'keyvaluestorage'
const KeyValueStorage = require('keyvaluestorage')
Package is ESM-only; require() will fail.

Initializes KeyValueStorage with in-memory SQLite, sets, gets, and removes an item.

import KeyValueStorage from 'keyvaluestorage'; // For Node.js, provide a database path (or ':memory:' for in-memory) const storage = new KeyValueStorage({ database: ':memory:', tableName: 'mystore' }); async function main() { await storage.setItem('user1', { name: 'Alice' }); const user = await storage.getItem('user1'); console.log(user); // { name: 'Alice' } await storage.removeItem('user1'); const keys = await storage.getKeys(); console.log(keys); // [] } main().catch(console.error);
Debug
Known issues
breakingYou must provide either `asyncStorage` (React Native) or `database` (Node.js) in options; otherwise an error is thrown.
fix
Ensure the correct platform adapter is passed. For browsers, no adapter is needed (uses localStorage automatically).
affects: >=0.0.1
deprecatedThe `database` option expects a path string; using an object or in-memory flag may be deprecated in future versions.
fix
Use `':memory:'` string for in-memory SQLite.
affects: <1.0.0
gotchaIn React Native, the `asyncStorage` option must be the default export from '@react-native-async-storage/async-storage', not the module itself.
fix
Use `import AsyncStorage from '@react-native-async-storage/async-storage'` and pass AsyncStorage.
affects: >=0.0.1
gotchaThe package only supports async/await, not synchronous operations; all methods return Promises.
fix
Always use await or .then() when calling storage methods.
affects: >=0.0.1
gotchaIn browser, the storage uses localStorage, but only string values are supported; objects are serialized via JSON.stringify/parse.
fix
Pass serializable objects; ensure getItem returns the parsed object.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: (0 , keyvaluestorage_1.default) is not a constructor
Using named import { KeyValueStorage } instead of default import
fix
Replace with: import KeyValueStorage from 'keyvaluestorage'
Error: You must provide either asyncStorage or database option
Missing required platform adapter in options object
fix
Pass `database: ':memory:'` for Node.js or `asyncStorage: AsyncStorage` for React Native
Module not found: Can't resolve 'sql.js'
Missing SQLite dependency when using Node.js platform
fix
Install sql.js or better-sqlite3: npm install sql.js
Cannot read property 'getItem' of undefined
Storage instance not created or options missing, leading to internal storage not initialized
fix
Ensure KeyValueStorage is instantiated with correct options and the promise resolves
Upgrade
Version history
0.7.1latest on npm
Audit
Dependencies
@react-native-async-storage/async-storageoptionalRequired for React Native platform
sql.js or better-sqlite3optionalRequired for Node.js platform to provide SQLite database
Agent activity
8 hits · last 30 days
node
8
Resources
keyvaluestorage — npm install keyvaluestorage · libregistry