localforage vs lowdb vs levelup vs node-persist vs pouchdb vs nedb
JavaScript Data Storage Libraries Comparison
1 Year
localforagelowdblevelupnode-persistpouchdbnedbSimilar Packages:
What's JavaScript Data Storage Libraries?

These libraries provide various solutions for data storage in JavaScript applications, catering to different needs such as local storage, persistence, and synchronization. They enable developers to manage data efficiently, whether in a server-side Node.js environment or client-side web applications. Each library has unique features and use cases, making it essential to choose the right one based on the specific requirements of your project.

NPM Package Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
localforage1,962,20025,079-2463 years agoApache-2.0
lowdb448,12921,66722.9 kB12a year agoMIT
levelup347,9884,085-03 years agoMIT
node-persist63,03172439.1 kB185 months agoMIT
pouchdb21,29616,9975.53 MB1576 months agoApache-2.0
nedb14,54813,518-2109 years agoSEE LICENSE IN LICENSE
Feature Comparison: localforage vs lowdb vs levelup vs node-persist vs pouchdb vs nedb

Storage Type

  • localforage:

    LocalForage abstracts different storage mechanisms like IndexedDB, WebSQL, and localStorage, allowing developers to use a simple API for asynchronous storage. It is primarily used for client-side applications needing offline capabilities.

  • lowdb:

    LowDB is a simple JSON database that stores data in a JSON file, making it easy to read and write. It is suitable for small projects and prototyping, where a lightweight solution is needed without complex setup.

  • levelup:

    LevelUP is a wrapper around LevelDB, providing a key-value store that is fast and efficient for large datasets. It is designed for server-side applications, allowing for complex data structures and high performance.

  • node-persist:

    Node-Persist is a key-value store that saves data to the file system, providing a simple way to persist data in Node.js applications. It is ideal for applications that require basic data storage without complex features.

  • pouchdb:

    PouchDB is a NoSQL database that can sync with CouchDB, allowing for offline data storage and synchronization across devices. It is designed for web and mobile applications that require robust data handling and offline capabilities.

  • nedb:

    NeDB is an embedded database that provides a MongoDB-like API for Node.js applications. It stores data in a file and supports indexing, making it suitable for applications that need a lightweight database with querying capabilities.

Ease of Use

  • localforage:

    LocalForage offers a simple and intuitive API that makes it easy for developers to store and retrieve data asynchronously, making it a great choice for web applications.

  • lowdb:

    LowDB is extremely easy to set up and use, with a minimalistic API that allows developers to read and write data in JSON format without much overhead.

  • levelup:

    LevelUP has a straightforward API that allows developers to perform CRUD operations easily. However, it requires some understanding of LevelDB concepts to utilize its full potential effectively.

  • node-persist:

    Node-Persist has a simple API for storing and retrieving key-value pairs, making it easy for developers to implement persistent storage in their applications.

  • pouchdb:

    PouchDB has a user-friendly API that simplifies data synchronization and offline storage, making it accessible for developers to implement complex features without much hassle.

  • nedb:

    NeDB provides a familiar MongoDB-like API, making it easy for developers who are already accustomed to MongoDB to use it without a steep learning curve.

Performance

  • localforage:

    LocalForage provides good performance for client-side storage, but its speed can vary depending on the underlying storage mechanism used by the browser.

  • lowdb:

    LowDB is not designed for high-performance applications, as it reads and writes data to a JSON file, which can become a bottleneck with larger datasets.

  • levelup:

    LevelUP is optimized for performance, especially with large datasets, as it leverages LevelDB's efficient storage and retrieval mechanisms, making it suitable for high-performance applications.

  • node-persist:

    Node-Persist is suitable for small-scale applications, but performance may degrade with larger datasets due to file system I/O operations.

  • pouchdb:

    PouchDB is designed for performance and can handle large datasets efficiently, especially with its ability to sync data with CouchDB.

  • nedb:

    NeDB offers decent performance for small to medium-sized datasets, but it may struggle with very large datasets due to its file-based storage approach.

Data Synchronization

  • localforage:

    LocalForage does not support data synchronization out of the box, but it can be used in conjunction with other libraries to achieve this functionality.

  • lowdb:

    LowDB does not offer data synchronization features, as it is intended for simple, local data storage without complex requirements.

  • levelup:

    LevelUP does not provide built-in data synchronization features, as it is primarily focused on local storage and retrieval.

  • node-persist:

    Node-Persist does not provide synchronization capabilities, focusing instead on simple key-value storage.

  • pouchdb:

    PouchDB excels in data synchronization, allowing seamless syncing with CouchDB and other PouchDB instances, making it ideal for applications that require offline capabilities and data consistency across devices.

  • nedb:

    NeDB does not natively support data synchronization, but it can be used in applications where data consistency is managed manually.

Use Cases

  • localforage:

    LocalForage is ideal for web applications that need to store user data offline, such as progressive web apps (PWAs) that require persistent storage across sessions.

  • lowdb:

    LowDB is perfect for small projects, prototypes, or applications that need a simple, file-based database without the overhead of a full database system.

  • levelup:

    LevelUP is best suited for applications that require a fast and efficient key-value store, such as caching, session storage, or managing large datasets in Node.js environments.

  • node-persist:

    Node-Persist is great for applications that need simple key-value storage, such as caching or storing user preferences in Node.js applications.

  • pouchdb:

    PouchDB is best for mobile and web applications that require robust offline capabilities and data synchronization across devices, making it ideal for collaborative applications.

  • nedb:

    NeDB is suitable for desktop applications or small server-side applications that require a lightweight database with a familiar API for MongoDB users.

How to Choose: localforage vs lowdb vs levelup vs node-persist vs pouchdb vs nedb
  • localforage:

    Select LocalForage if you are looking for a library that provides a simple API for asynchronous storage, supporting multiple backends like IndexedDB, WebSQL, and localStorage. It's perfect for web applications that require offline capabilities and a consistent API across different browsers.

  • lowdb:

    Opt for LowDB if you need a lightweight JSON database for small projects or prototyping. It is easy to set up and use, making it suitable for applications that require simple data storage without the overhead of a full database system.

  • levelup:

    Choose LevelUP if you need a simple and flexible way to work with LevelDB, especially for applications that require a fast key-value store with a focus on performance and scalability. It's ideal for Node.js applications that need to handle large amounts of data efficiently.

  • node-persist:

    Choose Node-Persist if you need a simple and persistent key-value store for Node.js applications. It is easy to use and provides a straightforward way to store data on the file system, making it suitable for small-scale applications or caching.

  • pouchdb:

    Select PouchDB if you need a powerful database that can sync with CouchDB and work offline. It is ideal for applications that require data synchronization across devices and offline capabilities, making it suitable for mobile and web applications.

  • nedb:

    Use NeDB if you want a lightweight, embedded database for Node.js applications that resembles MongoDB's API. It is suitable for applications that require a simple, file-based database with indexing and querying capabilities without the need for a full-fledged database server.

README for localforage

localForage

Build Status NPM version Dependency Status npm jsDelivr Hits minzipped size

localForage is a fast and simple storage library for JavaScript. localForage improves the offline experience of your web app by using asynchronous storage (IndexedDB or WebSQL) with a simple, localStorage-like API.

localForage uses localStorage in browsers with no IndexedDB or WebSQL support. See the wiki for detailed compatibility info.

To use localForage, just drop a single JavaScript file into your page:

<script src="localforage/dist/localforage.js"></script>
<script>localforage.getItem('something', myCallback);</script>

Try the live example.

Download the latest localForage from GitHub, or install with npm:

npm install localforage

Support

Lost? Need help? Try the localForage API documentation. localForage API文档也有中文版。

If you're having trouble using the library, running the tests, or want to contribute to localForage, please look through the existing issues for your problem first before creating a new one. If you still need help, feel free to file an issue.

How to use localForage

Callbacks vs Promises

Because localForage uses async storage, it has an async API. It's otherwise exactly the same as the localStorage API.

localForage has a dual API that allows you to either use Node-style callbacks or Promises. If you are unsure which one is right for you, it's recommended to use Promises.

Here's an example of the Node-style callback form:

localforage.setItem('key', 'value', function (err) {
  // if err is non-null, we got an error
  localforage.getItem('key', function (err, value) {
    // if err is non-null, we got an error. otherwise, value is the value
  });
});

And the Promise form:

localforage.setItem('key', 'value').then(function () {
  return localforage.getItem('key');
}).then(function (value) {
  // we got our value
}).catch(function (err) {
  // we got an error
});

Or, use async/await:

try {
    const value = await localforage.getItem('somekey');
    // This code runs once the value has been loaded
    // from the offline store.
    console.log(value);
} catch (err) {
    // This code runs if there were any errors.
    console.log(err);
}

For more examples, please visit the API docs.

Storing Blobs, TypedArrays, and other JS objects

You can store any type in localForage; you aren't limited to strings like in localStorage. Even if localStorage is your storage backend, localForage automatically does JSON.parse() and JSON.stringify() when getting/setting values.

localForage supports storing all native JS objects that can be serialized to JSON, as well as ArrayBuffers, Blobs, and TypedArrays. Check the API docs for a full list of types supported by localForage.

All types are supported in every storage backend, though storage limits in localStorage make storing many large Blobs impossible.

Configuration

You can set database information with the config() method. Available options are driver, name, storeName, version, size, and description.

Example:

localforage.config({
    driver      : localforage.WEBSQL, // Force WebSQL; same as using setDriver()
    name        : 'myApp',
    version     : 1.0,
    size        : 4980736, // Size of database, in bytes. WebSQL-only for now.
    storeName   : 'keyvaluepairs', // Should be alphanumeric, with underscores.
    description : 'some description'
});

Note: you must call config() before you interact with your data. This means calling config() before using getItem(), setItem(), removeItem(), clear(), key(), keys() or length().

Multiple instances

You can create multiple instances of localForage that point to different stores using createInstance. All the configuration options used by config are supported.

var store = localforage.createInstance({
  name: "nameHere"
});

var otherStore = localforage.createInstance({
  name: "otherName"
});

// Setting the key on one of these doesn't affect the other.
store.setItem("key", "value");
otherStore.setItem("key", "value2");

RequireJS

You can use localForage with RequireJS:

define(['localforage'], function(localforage) {
    // As a callback:
    localforage.setItem('mykey', 'myvalue', console.log);

    // With a Promise:
    localforage.setItem('mykey', 'myvalue').then(console.log);
});

TypeScript

If you have the allowSyntheticDefaultImports compiler option set to true in your tsconfig.json (supported in TypeScript v1.8+), you should use:

import localForage from "localforage";

Otherwise you should use one of the following:

import * as localForage from "localforage";
// or, in case that the typescript version that you are using
// doesn't support ES6 style imports for UMD modules like localForage
import localForage = require("localforage");

Framework Support

If you use a framework listed, there's a localForage storage driver for the models in your framework so you can store data offline with localForage. We have drivers for the following frameworks:

If you have a driver you'd like listed, please open an issue to have it added to this list.

Custom Drivers

You can create your own driver if you want; see the defineDriver API docs.

There is a list of custom drivers on the wiki.

Working on localForage

You'll need node/npm and bower.

To work on localForage, you should start by forking it and installing its dependencies. Replace USERNAME with your GitHub username and run the following:

# Install bower globally if you don't have it:
npm install -g bower

# Replace USERNAME with your GitHub username:
git clone git@github.com:USERNAME/localForage.git
cd localForage
npm install
bower install

Omitting the bower dependencies will cause the tests to fail!

Running Tests

You need PhantomJS installed to run local tests. Run npm test (or, directly: grunt test). Your code must also pass the linter.

localForage is designed to run in the browser, so the tests explicitly require a browser environment. Local tests are run on a headless WebKit (using PhantomJS).

When you submit a pull request, tests will be run against all browsers that localForage supports on Travis CI using Sauce Labs.

Library Size

As of version 1.7.3 the payload added to your app is rather small. Served using gzip compression, localForage will add less than 10k to your total bundle size:

minified
`~29kB`
gzipped
`~8.8kB`
brotli'd
`~7.8kB`

License

This program is free software; it is distributed under an Apache License.


Copyright (c) 2013-2016 Mozilla (Contributors).