sqlite3 vs lowdb vs levelup vs mongodb-memory-server vs pouchdb vs nedb
Node.js Database Libraries Comparison
3 Years
sqlite3lowdblevelupmongodb-memory-serverpouchdbnedbSimilar Packages:
What's Node.js Database Libraries?

Node.js Database Libraries are tools that allow Node.js applications to interact with various types of databases, including relational, NoSQL, and in-memory databases. These libraries provide APIs for performing CRUD (Create, Read, Update, Delete) operations, managing connections, and executing queries. They abstract the complexities of database interactions, making it easier for developers to integrate data storage and retrieval functionalities into their applications. Examples include mongoose for MongoDB, sequelize for SQL databases, and knex for query building.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
sqlite31,618,942
6,3683.35 MB1652 years agoBSD-3-Clause
lowdb910,537
22,20322.9 kB162 years agoMIT
levelup782,100
4,084-04 years agoMIT
mongodb-memory-server744,525
2,7284.58 kB184 days agoMIT
pouchdb47,916
17,3495.53 MB178a year agoApache-2.0
nedb38,187
13,555-2089 years agoSEE LICENSE IN LICENSE
Feature Comparison: sqlite3 vs lowdb vs levelup vs mongodb-memory-server vs pouchdb vs nedb

Database Type

  • sqlite3:

    sqlite3 is a Node.js driver for SQLite, a self-contained, serverless, and lightweight relational database. It provides a simple API for executing SQL queries and managing database files, making it a popular choice for small to medium-sized applications that require a reliable and easy-to-use database solution.

  • lowdb:

    lowdb is a small local JSON database powered by Lodash. It is a simple and lightweight solution for storing data in JSON format, making it ideal for small projects, prototypes, or applications that need a quick and easy way to manage data without the complexity of a full database system.

  • levelup:

    levelup is a Node.js library that provides a simple, high-level API for interacting with LevelDB and other key-value stores. It is designed for applications that require fast, low-latency access to data stored as key-value pairs.

  • mongodb-memory-server:

    mongodb-memory-server is a Node.js package that allows you to spin up a MongoDB server in memory for testing purposes. It is particularly useful for automated tests, as it eliminates the need for a separate MongoDB instance and allows for quick setup and teardown of the database.

  • pouchdb:

    pouchdb is an open-source JavaScript database that syncs with CouchDB and other compatible servers. It is designed for web and mobile applications, providing offline storage and synchronization capabilities, making it ideal for apps that need to work seamlessly without an internet connection.

  • nedb:

    nedb is a lightweight, embedded NoSQL database for Node.js applications. It stores data in JSON format and provides a simple API for CRUD operations, making it easy to integrate into projects that require a fast and efficient way to manage data without the overhead of a full database server.

Use Case

  • sqlite3:

    sqlite3 is a great choice for applications that need a lightweight relational database with full SQL support, such as mobile apps, desktop applications, and small web applications.

  • lowdb:

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

  • levelup:

    levelup is ideal for applications that require fast, low-latency access to key-value data, such as caching, real-time analytics, and lightweight data storage solutions.

  • mongodb-memory-server:

    mongodb-memory-server is designed for testing environments where you need a temporary MongoDB instance for running automated tests without the overhead of managing a real database server.

  • pouchdb:

    pouchdb is ideal for web and mobile applications that require offline data storage and synchronization with a remote database, providing a seamless experience for users with intermittent internet connectivity.

  • nedb:

    nedb is suitable for small to medium-sized applications that need a simple, embedded database for quick data access, such as desktop applications, small web apps, and IoT devices.

Data Storage

  • sqlite3:

    sqlite3 stores data in a structured format using tables, rows, and columns, allowing for complex queries and data relationships.

  • lowdb:

    lowdb stores data in JSON format within a single file, allowing for easy read and write operations using a simple API.

  • levelup:

    levelup stores data as key-value pairs in LevelDB or other compatible backends, providing fast read and write operations with low latency.

  • mongodb-memory-server:

    mongodb-memory-server stores data in a MongoDB-compatible format, allowing you to perform standard MongoDB operations in an in-memory environment.

  • pouchdb:

    pouchdb stores data in a JSON format, supporting both local storage and synchronization with remote CouchDB-compatible databases.

  • nedb:

    nedb stores data in JSON format, either in memory or on disk, depending on the configuration, allowing for fast access and simple data management.

Code Example

  • sqlite3:

    sqlite3 Example

    const sqlite3 = require('sqlite3').verbose();
    const db = new sqlite3.Database(':memory:');
    
    db.serialize(() => {
      db.run('CREATE TABLE user (id INT, name TEXT)');
      const stmt = db.prepare('INSERT INTO user VALUES (?, ?)');
      stmt.run(1, 'Alice');
      stmt.finalize();
    
      db.each('SELECT * FROM user', (err, row) => {
        console.log(row);
      });
    });
    
    db.close();
    
  • lowdb:

    lowdb Example

    const { Low, JSONFile } = require('lowdb');
    
    const db = new Low(new JSONFile('db.json'));
    
    db.read();
    
    db.data ||= { posts: [] };
    
    db.data.posts.push({ id: 1, title: 'Lowdb is awesome' });
    
    db.write();
    
    console.log(db.data);
    
  • levelup:

    levelup Example

    const levelup = require('levelup');
    const leveldown = require('leveldown');
    
    const db = levelup(leveldown('./mydb'));
    
    db.put('key1', 'value1', (err) => {
      if (err) return console.error('Error writing to database:', err);
      db.get('key1', (err, value) => {
        if (err) return console.error('Error reading from database:', err);
        console.log('Retrieved value:', value);
      });
    });
    
  • mongodb-memory-server:

    mongodb-memory-server Example

    const { MongoMemoryServer } = require('mongodb-memory-server');
    const mongoose = require('mongoose');
    
    const startServer = async () => {
      const mongoServer = await MongoMemoryServer.create();
      await mongoose.connect(mongoServer.getUri());
      console.log('Connected to in-memory MongoDB');
    };
    
    startServer();
    
  • pouchdb:

    pouchdb Example

    const PouchDB = require('pouchdb');
    const db = new PouchDB('mydb');
    
    db.put({ _id: 'doc1', title: 'Hello, PouchDB!' }).then(() => {
      return db.get('doc1');
    }).then((doc) => {
      console.log('Retrieved document:', doc);
    }).catch((err) => {
      console.error('Error:', err);
    });
    
  • nedb:

    nedb Example

    const Datastore = require('nedb');
    const db = new Datastore({ filename: 'data.db', autoload: true });
    
    db.insert({ name: 'Alice' }, (err, newDoc) => {
      if (err) console.error(err);
      console.log('Inserted:', newDoc);
    });
    
    db.find({ name: 'Alice' }, (err, docs) => {
      if (err) console.error(err);
      console.log('Found:', docs);
    });
    
How to Choose: sqlite3 vs lowdb vs levelup vs mongodb-memory-server vs pouchdb vs nedb
  • sqlite3:

    Choose sqlite3 if you need a self-contained, serverless SQL database that is easy to set up and use. It is suitable for small to medium-sized applications, mobile apps, and projects that require a lightweight relational database with full SQL support.

  • lowdb:

    Choose lowdb if you need a lightweight, file-based JSON database for small projects or prototyping. It is easy to set up and use, making it ideal for applications that do not require a full-fledged database system.

  • levelup:

    Choose levelup if you need a simple, high-level API for interacting with LevelDB or other key-value stores. It is suitable for applications that require fast, low-latency data access with a focus on simplicity and performance.

  • mongodb-memory-server:

    Choose mongodb-memory-server if you need a lightweight, in-memory MongoDB instance for testing purposes. It is perfect for automated tests and CI/CD pipelines, allowing you to run tests without needing a real MongoDB server.

  • pouchdb:

    Choose pouchdb if you need a client-side database that syncs with CouchDB and other compatible servers. It is ideal for applications that require offline capabilities and data synchronization across devices.

  • nedb:

    Choose nedb if you need a simple, embedded NoSQL database for Node.js applications. It is lightweight, fast, and stores data in JSON format, making it suitable for small to medium-sized applications that require quick data access without the overhead of a full database server.

README for sqlite3

⚙️ node-sqlite3

Asynchronous, non-blocking SQLite3 bindings for Node.js.

Latest release Build Status FOSSA Status N-API v3 Badge N-API v6 Badge

Features

Installing

You can use npm or yarn to install sqlite3:

  • (recommended) Latest published package:
npm install sqlite3
# or
yarn add sqlite3
  • GitHub's master branch: npm install https://github.com/tryghost/node-sqlite3/tarball/master

Prebuilt binaries

sqlite3 v5+ was rewritten to use Node-API so prebuilt binaries do not need to be built for specific Node versions. sqlite3 currently builds for both Node-API v3 and v6. Check the Node-API version matrix to ensure your Node version supports one of these. The prebuilt binaries should be supported on Node v10+.

The module uses prebuild-install to download the prebuilt binary for your platform, if it exists. These binaries are hosted on GitHub Releases for sqlite3 versions above 5.0.2, and they are hosted on S3 otherwise. The following targets are currently provided:

  • darwin-arm64
  • darwin-x64
  • linux-arm64
  • linux-x64
  • linuxmusl-arm64
  • linuxmusl-x64
  • win32-ia32
  • win32-x64

Unfortunately, prebuild cannot differentiate between armv6 and armv7, and instead uses arm as the {arch}. Until that is fixed, you will still need to install sqlite3 from source.

Support for other platforms and architectures may be added in the future if CI supports building on them.

If your environment isn't supported, it'll use node-gyp to build SQLite, but you will need to install a C++ compiler and linker.

Other ways to install

It is also possible to make your own build of sqlite3 from its source instead of its npm package (See below.).

The sqlite3 module also works with node-webkit if node-webkit contains a supported version of Node.js engine. (See below.)

SQLite's SQLCipher extension is also supported. (See below.)

API

See the API documentation in the wiki.

Usage

Note: the module must be installed before use.

const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database(':memory:');

db.serialize(() => {
    db.run("CREATE TABLE lorem (info TEXT)");

    const stmt = db.prepare("INSERT INTO lorem VALUES (?)");
    for (let i = 0; i < 10; i++) {
        stmt.run("Ipsum " + i);
    }
    stmt.finalize();

    db.each("SELECT rowid AS id, info FROM lorem", (err, row) => {
        console.log(row.id + ": " + row.info);
    });
});

db.close();

Source install

To skip searching for pre-compiled binaries, and force a build from source, use

npm install --build-from-source

The sqlite3 module depends only on libsqlite3. However, by default, an internal/bundled copy of sqlite will be built and statically linked, so an externally installed sqlite3 is not required.

If you wish to install against an external sqlite then you need to pass the --sqlite argument to npm wrapper:

npm install --build-from-source --sqlite=/usr/local

If building against an external sqlite3 make sure to have the development headers available. Mac OS X ships with these by default. If you don't have them installed, install the -dev package with your package manager, e.g. apt-get install libsqlite3-dev for Debian/Ubuntu. Make sure that you have at least libsqlite3 >= 3.6.

Note, if building against homebrew-installed sqlite on OS X you can do:

npm install --build-from-source --sqlite=/usr/local/opt/sqlite/

Custom file header (magic)

The default sqlite file header is "SQLite format 3". You can specify a different magic, though this will make standard tools and libraries unable to work with your files.

npm install --build-from-source --sqlite_magic="MyCustomMagic15"

Note that the magic must be exactly 15 characters long (16 bytes including null terminator).

Building for node-webkit

Because of ABI differences, sqlite3 must be built in a custom to be used with node-webkit.

To build sqlite3 for node-webkit:

  1. Install nw-gyp globally: npm install nw-gyp -g (unless already installed)

  2. Build the module with the custom flags of --runtime, --target_arch, and --target:

NODE_WEBKIT_VERSION="0.8.6" # see latest version at https://github.com/rogerwang/node-webkit#downloads
npm install sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)

You can also run this command from within a sqlite3 checkout:

npm install --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)

Remember the following:

  • You must provide the right --target_arch flag. ia32 is needed to target 32bit node-webkit builds, while x64 will target 64bit node-webkit builds (if available for your platform).

  • After the sqlite3 package is built for node-webkit it cannot run in the vanilla Node.js (and vice versa).

    • For example, npm test of the node-webkit's package would fail.

Visit the “Using Node modules” article in the node-webkit's wiki for more details.

Building for SQLCipher

For instructions on building SQLCipher, see Building SQLCipher for Node.js. Alternatively, you can install it with your local package manager.

To run against SQLCipher, you need to compile sqlite3 from source by passing build options like:

npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/

node -e 'require("sqlite3")'

If your SQLCipher is installed in a custom location (if you compiled and installed it yourself), you'll need to set some environment variables:

On OS X with Homebrew

Set the location where brew installed it:

export LDFLAGS="-L`brew --prefix`/opt/sqlcipher/lib"
export CPPFLAGS="-I`brew --prefix`/opt/sqlcipher/include/sqlcipher"
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix`

node -e 'require("sqlite3")'

On most Linuxes (including Raspberry Pi)

Set the location where make installed it:

export LDFLAGS="-L/usr/local/lib"
export CPPFLAGS="-I/usr/local/include -I/usr/local/include/sqlcipher"
export CXXFLAGS="$CPPFLAGS"
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/local --verbose

node -e 'require("sqlite3")'

Custom builds and Electron

Running sqlite3 through electron-rebuild does not preserve the SQLCipher extension, so some additional flags are needed to make this build Electron compatible. Your npm install sqlite3 --build-from-source command needs these additional flags (be sure to replace the target version with the current Electron version you are working with):

--runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers

In the case of MacOS with Homebrew, the command should look like the following:

npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers

Testing

npm test

Contributors

Acknowledgments

Thanks to Orlando Vazquez, Eric Fredricksen and Ryan Dahl for their SQLite bindings for node, and to mraleph on Freenode's #v8 for answering questions.

This module was originally created by Mapbox & is now maintained by Ghost.

Changelog

We use GitHub releases for notes on the latest versions. See CHANGELOG.md in git history for details on older versions.

License

node-sqlite3 is BSD licensed.

FOSSA Status