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.
- 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.
- Node.js installed on your machine.
- Basic knowledge of TypeScript and Node.js.
To get started with NodeStorage in your package
npm install node-persist-manager
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.
});
Use the manager to create a new storage context.
const myStorage = await storageManager.createStorage('myStorageName');
Using the Storage:
await myStorage.set('myKey', 'myValue');
const value = await myStorage.get('myKey');
console.log(value); // Outputs: 'myValue'
await myStorage.remove('myKey');
await myStorage.clear();
-
async createStorage(storageName: string): Promise<NodeStorage>
-
async removeStorage(storageName: string): Promise<boolean>
-
async logStorage(): Promise<void>
-
async getStorageNames(): Promise<NodeStorageName[]>
-
async logStorage(): Promise<void>
-
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>
Contributions to NodeStorage are welcome.
This project is licensed under the MIT License - see the LICENSE file for details.
Thanks to node-persist for providing the underlying storage mechanism.