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

@heisenware/storage

v1.2.2

Published

Efficient and robust JSON file storage

Readme

Persistent JSON Storage

A lightweight, class-based JSON storage module for Node.js that uses the filesystem for persisting structured key-value data. Designed for atomic writes, cross-instance sync, and watch-based reactivity, it's perfect for local persistence, caching, or lightweight state management.


🚀 Features

  • Safe, atomic writes (temp file + rename strategy)
  • Supports nested folders for scoped persistence
  • Queue-based concurrency ensures safe access per file
  • Multi-instance aware: storage stays in sync across instances
  • Real-time sync using filesystem watchers (chokidar)
  • Automatic cleanup of temp files
  • Efficient key indexing via MD5-hashed filenames

📦 Installation

npm install @heisenware/storage

✨ Usage

const Storage = require('@heisenware/storage')

const storage = new Storage({ dir: '/tmp/my-app-store' })

await storage.setItem('user123', { name: 'Alice', active: true })
const user = await storage.getItem('user123')
console.log(user) // { name: 'Alice', active: true }

await storage.removeItem('user123')
await storage.clear() // clears all stored entries

📁 Folder Support

Store and query items within custom subfolders:

await storage.setItem('session42', { token: 'abc' }, { folder: 'sessions' })
const keys = await storage.keys('sessions') // ['session42']

🧠 Internal Design

  • Files are named using MD5(key) to avoid path issues.
  • Each entry is stored as a single JSON file: { key, value }.
  • Temp files use .tmp-<timestamp> suffix and are cleaned if needed.
  • chokidar watches for external changes and updates all instances.

🛠 API

new Storage({ dir, log })

Create a storage instance.

  • dir: absolute path to storage directory
  • log: optional logger (defaults to console)

setItem(key, value, { folder })

Persist a key-value pair.

getItem(key)

Retrieve a previously stored value.

removeItem(key)

Delete an entry.

keys(folder)

List all stored keys, optionally scoped to a folder.

clear({ folder })

Clear all entries (optionally in a subfolder).


🔒 Atomicity & Concurrency

Each file operation uses a per-file async queue, ensuring that overlapping reads/writes don't corrupt files. This package is race-protected against concurrent file access withing the scope of a single-process.


✅ Tests

Includes a full integration test suite for reading, writing, concurrency, and multi-instance interaction.

To run:

npm test

⚠️ Known Limitation: OS-native bulk-clear and File Watchers

Due to limitations in file system watchers like chokidar, bulk operations such as for example fs-extra’s emptyDir do not trigger file removal events.

When these operations are executed externally, the storage instance may loose synchronization. In that case, it is advisable to re-create the instance which leads to a re-synchronization.


📜 License

MIT – Built to be used in open-source and commercial projects alike.


💡 Contributing

Contributions, bug reports, and PRs are welcome. Let’s make local storage a breeze for Node.js!