node-persist-manager
v1.0.8
Published
Asyncronous Node.js storage manager in type script
Downloads
10,144
Maintainers
Readme
NodeStorageManager and NodeStorage
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.
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
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.