npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

nope.db

v1.0.1

Published

A modern, simple, and async JSON database for Node.js with zero dependencies and a data-safe queue.

Readme

nope.db npm version npm downloads install size GitHub License

A modern, simple, and asynchronous JSON database for Node.js. Zero dependencies, dual-module (ESM/CJS) support, and a robust queueing system to prevent data corruption.

Features

  • Asynchronous: All methods are Promise-based (async/await).
  • Data Safe: Uses an atomic write queue to prevent data corruption from concurrent writes.
  • Dual Module: Supports both ES Modules (import) and CommonJS (require).
  • Zero Dependencies: Lightweight and clean.
  • Nested Data: Access and manage nested objects with ease using a separator (e.g., user.settings.theme).

Installation

$ npm install nope.db

Getting Started

All database operations are asynchronous and return a Promise.

ES Modules (import)

import { NopeDB } from 'nope.db';

// All settings are optional
const db = new NopeDB({
  path: './mydb.json', // defaults to './db.json'
  spaces: 2,          // defaults to 2 (for JSON formatting)
  separator: '.'      // defaults to '.'
});

async function main() {
  try {
    await db.set('user.1', { name: 'nopeion', role: 'admin' });
    
    // This will be stored in 'mydb.json' as:
    // { 
    //   "user": { 
    //     "1": { "name": "nopeion", "role": "admin" } 
    //   } 
    // }

    const user = await db.get('user.1');
    console.log(user); // { name: 'nopeion', role: 'admin' }

    // Access nested properties using the separator
    const role = await db.get('user.1.role');
    console.log(role); // 'admin'
    
  } catch (error) {
    console.error("Database operation failed:", error);
  }
}

main();

CommonJS (require)

const { NopeDB } = require('nope.db');

const db = new NopeDB(); // Using all default settings

(async () => {
  try {
    await db.set('counter', 10);
    await db.add('counter', 5);
    const count = await db.get('counter');
    console.log(count); // 15
  } catch (error) {
    console.error("Database operation failed:", error);
  }
})();

API Reference

All methods are asynchronous and return a Promise.

new NopeDB(settings?)

Creates a new database instance.

  • settings (optional): An object with the following properties:
    • path (string): Path to the database file.
      • Default: './db.json'
    • spaces (number): Number of spaces for JSON formatting.
      • Default: 2
    • separator (string): Character to use for nested object access.
      • Default: '.'

set(id, value)

Sets or updates an element in the database.

  • Returns: Promise<any> - The value that was set.

get(id)

Gets an element from the database.

  • Returns: Promise<any> - The requested data, or null if not found.

add(id, value)

Adds a number to an element. If the element doesn't exist, it will be created.

  • Returns: Promise<number> - The total result.
  • Throws: DatabaseError if the existing data or the value is not a number.

subtract(id, value)

Subtracts a number from an element.

  • Returns: Promise<number> - The remaining result.
  • Throws: DatabaseError if the existing data or the value is not a number.

has(id)

Checks if data exists in the database.

  • Returns: Promise<boolean> - true or false.

push(id, value)

Pushes an element into an array. If the array doesn't exist, it will be created.

  • Returns: Promise<any[]> - The updated array.
  • Throws: DatabaseError if the existing data is not an array.

delete(id)

Deletes an element from the database.

  • Returns: Promise<boolean> - true if deletion was successful, false if not found.

all()

Returns all data in the database.

  • Returns: Promise<object> - The complete database object.

clear(options)

Clears all data in the database.

  • options (object): Must be { confirm: true } to prevent accidental deletion.
  • Returns: Promise<true>
  • Throws: DatabaseError if confirmation is not provided.

backup(filePath)

Creates a backup of the current database to a new file.

  • filePath (string): The full path for the backup file (e.g., './my-backup.json').
  • Returns: Promise<true>

loadBackup(filePath)

Loads data from a backup file, overwriting the current database.

  • filePath (string): The full path of the backup file to load.
  • Returns: Promise<true>

Aliases

  • fetch(id): Alias for get(id).
  • remove(id): Alias for delete(id).
  • reset(options): Alias for clear(options).

Author

nopeion