smem
v0.0.7
Published
Shared memory between async processes
Downloads
17
Maintainers
Readme
SMem
Description
A lightweight, zero-dependency module that provides shared memory between asynchronous processes in Node.js applications.
Installation
npm install smemUsage
Basic Example
import SMem from 'smem';
// Create shared memory instance with default workspace
const mem = new SMem();
// Set up an async process to retrieve data
(async () => {
try {
// Wait for the value to be set (max 5 seconds by default)
const value = await mem.get('my-key');
console.log('Value retrieved:', value);
} catch (error) {
console.error('Error retrieving value:', error.message);
}
})();
// Set the value after a delay
setTimeout(() => {
mem.set('my-key', 'hello world');
}, 1000);Advanced Usage
import SMem from 'smem';
// Create memory instances for different workspaces
const userMem = new SMem('users');
const cacheMem = new SMem('cache');
// Get an existing value from the users workspace with custom settings
// Parameters: key, checkInterval (ms), timeout (ms)
const user = await userMem.get('user-123', 100, 3000);
// Store a value in the cache workspace
cacheMem.set('recent-search', { query: 'nodejs shared memory', results: 42 });License
MIT © 2018 - 2025 Volodymyr Sichka
