Registry / storage / localforage

localforage

JSON →
library1.10.0jsnpmunverified

localForage is a fast and simple offline storage library that provides an asynchronous, localStorage-like API using IndexedDB, WebSQL, or localStorage as fallback. Current stable version is 1.10.0, with maintenance-level updates. It simplifies client-side storage by automatically selecting the best available backend and supporting promises, callbacks, and async/await. Key differentiator: works with all modern browsers, handles Blobs and TypedArrays, and has a tiny footprint (~1.2KB gzipped).

npm install localforage
INSTALL
IMPORT
SIG · LOCALFORAGE
L
localforage
storagejavascriptv1.10.0
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.

localforage (default)
import localforage from 'localforage'
import { localforage } from 'localforage'
ESM default import; TypeScript types are included.
localforage (require)
const localforage = require('localforage')
const localforage = require('localforage').default
CommonJS default export; no .default needed.
localforage (script tag)
<script src="node_modules/localforage/dist/localforage.js"></script>
<script src="localforage.min.js"></script>
Global variable `localforage` is exposed; no import needed.

Quickstart example using async/await to get or set a value in localForage.

const localforage = require('localforage'); async function main() { const value = await localforage.getItem('key'); if (value === null) { console.log('Key not found, setting...'); await localforage.setItem('key', 'value'); } else { console.log('Found value:', value); } } main().catch(console.error);
Debug
Known issues
breakinglocalforage.setDriver('localStorageWrapper') will fail silently if the driver is not available, using fallback instead.
fix
Use `localforage.ready()` to detect the actual driver or use `localforage.supports(driverName)` before calling setDriver.
affects: >=1.0.0
deprecatedWebSQL is deprecated in most browsers and may be removed; localForage may drop support in future versions.
fix
Use IndexedDB as preferred backend; avoid relying on WebSQL.
affects: >=1.9.0
gotchalocalStorage serializes all values to JSON; storing Blobs or TypedArrays requires the IndexedDB or WebSQL backend.
fix
Ensure that the driver supports the data type; use `localforage.driver()` to check which driver is active.
affects: all
gotchaWhen using callbacks, the error-first pattern is used; omitting the callback may cause unhandled rejections in promise mode.
fix
Always pass a callback or use .catch() to handle errors; mixing callbacks and promises can lead to unexpected behavior.
affects: all
Errors
Common errors & fixes
Uncaught TypeError: localforage.getItem is not a function
localforage is not imported correctly, or the script is loaded before localforage is defined.
fix
Use `import localforage from 'localforage'` or `const localforage = require('localforage')`; ensure script tag is placed after the library.
localforage is not defined
localforage library not loaded (script tag missing or wrong path).
fix
Add a script tag pointing to localforage's dist file, e.g., `<script src="node_modules/localforage/dist/localforage.js"></script>`.
Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.
Multiple simultaneous operations on the same database instance without proper synchronization.
fix
Use `localforage.ready()` to wait for initialization, or use promises to chain operations.
Upgrade
Version history
1.10.0latest on npm
Audit
Dependencies
lierequiredLocalForage uses lie as a polyfill for Promises in older browsers (IE10/11, older Android). Included in bundle, not a runtime peer dependency.
Agent activity
24 hits · last 30 days
node
24
Resources
localforage — npm install localforage · libregistry