JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5819
  • Score
    100M100P100Q121297F
  • License MIT

Asyncronous Node.js storage manager in type script

Package Exports

  • node-persist-manager
  • node-persist-manager/dist/nodeStorage.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-persist-manager) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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.