Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

node-persist-manager

Luligu13.8kMIT2.0.0TypeScript support: included

Asyncronous Node.js storage manager in type script

node-persist, persist, storage, context, NodeStorageManager, NodeStorage

readme

NodeStorageManager and NodeStorage

npm version npm downloads Node.js CI CodeQL codecov


NodeStorage is a lightweight, file-based storage management system for Node.js, built on top of node-persist. It allows for easy and intuitive handling of persistent key-value storage directly within your Node.js applications. This system is ideal for small to medium-sized projects requiring simple data persistence without the overhead of a database system.

If you like this project and find it useful, please consider giving it a star on GitHub at https://github.com/Luligu/node-persist-manager and sponsoring it.

Buy me a coffee

Features

  • Simple and intuitive API for data storage and retrieval.
  • Asynchronous data handling.
  • Customizable storage directories for isolated storage contexts.
  • Built-in logging capabilities for monitoring storage initialization and operations.
  • Comprehensive test suite using Jest to ensure reliability and performance.
  • Detailed documentation with JSDoc for better developer experience.

Getting Started

Prerequisites

  • Node.js installed on your machine.
  • Basic knowledge of TypeScript and Node.js.

Installation

To get started with NodeStorage in your package

npm install node-persist-manager

TypeScript & ESM Support

This package is written in TypeScript and distributed as an ECMAScript module (ESM). You should use import statements to use it in your project:

import { NodeStorageManager, NodeStorage } from 'node-persist-manager';
  • If you are using CommonJS, consider using dynamic import() or transpiling your code to ESM.
  • Type definitions are included out of the box for TypeScript users.

Usage

Initializing NodeStorageManager:

Create an instance of NodeStorageManager to manage your storage instances.

import { NodeStorageManager, NodeStorage } from 'node-persist-manager';
const storageManager = new NodeStorageManager({
  dir: 'path/to/storage/directory', // Optional: Customize the storage directory.
  logging: true, // Optional: Enable logging.
});

Creating a Storage Instance:

Use the manager to create a new storage context.

const myStorage = await storageManager.createStorage('myStorageName');

Using the Storage:

Set a value:

await myStorage.set('myKey', 'myValue');

Get a value:

const value = await myStorage.get('myKey');
console.log(value); // Outputs: 'myValue'

Remove a value:

await myStorage.remove('myKey');

Clear the storage:

await myStorage.clear();

API Reference

NodeStorageManager methods:

  • async createStorage(storageName: string): Promise<NodeStorage>

  • async removeStorage(storageName: string): Promise<boolean>

  • async logStorage(): Promise<void>

  • async getStorageNames(): Promise<NodeStorageName[]>

  • async logStorage(): Promise<void>

NodeStorage methods:

  • async set<T = any>(key: NodeStorageKey, value: T): Promise<void>

  • async get<T = any>(key: NodeStorageKey, defaultValue?: T): Promise<T>

  • async remove(key: NodeStorageKey): Promise<void>

  • async clear(): Promise<void>

  • async logStorage(): Promise<void>

Contributing

Contributions to NodeStorage are welcome.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Thanks to node-persist for providing the underlying storage mechanism.

changelog

NodeStorageManager and NodeStorage Changelog

All notable changes to this project will be documented in this file.

If you like this project and find it useful, please consider giving it a star on GitHub at https://github.com/Luligu/node-persist-manager and sponsoring it.

Buy me a coffee

[2.0.0] - 2025-06-22

  • [init]: Release 2.0.0