Registry / storage / node-global-storage

node-global-storage

JSON →
library3.0.1jsnpmunverified

Global data storage manager for Node.js. Current version is 3.0.1, released with full TypeScript support, ESModules compatibility, zero dependencies, and 100% test coverage. Provides a simple key-value store with metadata, protection, and default options. Unlike other global state solutions, it wraps the storage in an abstraction layer with TypeScript generics, metadata tracking, and protection flags. The API is minimal and focused on global variable management without external dependencies. Maintained by jhereu with active releases.

npm install node-global-storage
INSTALL
IMPORT
SIG · NODE-GLOBAL-STORAG
N
node-global-storage
storagejavascriptv3.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

setValue
import { setValue } from 'node-global-storage'
const setValue = require('node-global-storage').setValue
ESM import is preferred. CommonJS requires destructuring the require result.
getValue
import { getValue } from 'node-global-storage'
import getValue from 'node-global-storage'
getValue is a named export, not default. Use destructuring.
flush
import { flush } from 'node-global-storage'
const flush = require('node-global-storage/flush')
All functions are exported from the main module. No subpath exports.

Basic usage: set, get, check, unset, flush, and options with TypeScript generics. Shows common operations.

import { setValue, getValue, isSet, unsetValue, flush, getAllValues } from 'node-global-storage'; // Set a value setValue('apiKey', 'abc123'); // Get the value const key = getValue<string>('apiKey'); console.log(key); // 'abc123' // Check existence console.log(isSet('apiKey')); // true // Unset a specific key unsetValue('apiKey'); // Clear all stored data flush(); // Set with options setValue('config', { theme: 'dark' }, { protect: true }); // Get all stored values console.log(getAllValues()); // Get metadata import { getMetadata } from 'node-global-storage'; const meta = getMetadata('config'); console.log(meta.protected); // true
Debug
Known issues
breakingVersion 3.x rewrote the package from scratch. API is similar but not identical to 2.x. Method signatures changed for setOptions and extended TypeScript generics.
fix
Review the new API docs. The setDefaultOption method replaces previous option configuration. Type parameters may be required now.
affects: >=3.0.0
deprecatedVersion 2.x had a different set of methods (e.g., setGlobal, getGlobal). These are removed in 3.x.
fix
Migrate to 3.x using the new method names: setValue, getValue, etc.
affects: >=2.0.0 <3.0.0
gotchasetValue returns the value that was set, but with TypeScript generics you must specify the type explicitly or it will be inferred as unknown.
fix
Use setValue<string>('key', 'value') or setValue('key', 'value') TypeScript will infer if the value matches.
affects: >=3.0.0
gotchagetValue does not throw if key does not exist; it returns undefined. Check existence with isSet before using.
fix
Use isSet(key) to check before calling getValue, or handle potential undefined.
affects: >=3.0.0
gotchaflush() with options differs from 2.x. In 3.x, FlushOptions includes an 'onlyUnprotected' flag instead of 'filter'.
fix
Use flush({ onlyUnprotected: true }) instead of flush({ filter: ... }) if migrating from 2.x.
affects: >=3.0.0
Errors
Common errors & fixes
Cannot find module 'node-global-storage' or its corresponding type declarations.
TypeScript project may not have @types/node-global-storage (unnecessary as package ships types).
fix
Ensure TypeScript is configured correctly. Package has built-in types. No need for separate @types package. Try reinstalling: npm install --save node-global-storage
TypeScript error: Property 'setValue' does not exist on type 'typeof import("node-global-storage")'
Using default import instead of named import.
fix
Change import statement to: import { setValue } from 'node-global-storage'
Uncaught ReferenceError: require is not defined
Using CommonJS require in an ES module context.
fix
Use import syntax: import { getValue } from 'node-global-storage' or switch to CommonJS.
TypeError: setValue is not a function
Attempting to call setValue as a default export or using wrong import pattern.
fix
Use named import: import { setValue } from 'node-global-storage'
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
20
Resources
node-global-storage — npm install node-global-storage · libregistry