{"id":48779,"library":"node-storage-shim","title":"node-storage-shim","description":"An in-memory implementation of the W3C Storage Interface (localStorage/sessionStorage) for use as a shim in Node.js environments, primarily for unit testing. v2.0.1 (March 2020) is the latest stable release. It uses Proxy (since v2.0.0) to allow direct property access while maintaining the storage API. It does not persist data to disk and does not implement the 'storage' event. Lightweight, TypeScript declarations included.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/mnahkies/node-storage-shim","tags":["javascript","typescript"],"install":[{"cmd":"npm install node-storage-shim","lang":"bash","label":"npm"},{"cmd":"yarn add node-storage-shim","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-storage-shim","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export; named import destructuring is incorrect. CommonJS require should be const StorageShim = require('node-storage-shim')","wrong":"const { StorageShim } = require('node-storage-shim')","symbol":"StorageShim","correct":"import StorageShim from 'node-storage-shim'"},{"note":"Correct CommonJS pattern; named destructuring is wrong.","wrong":"const { StorageShim } = require('node-storage-shim')","symbol":"StorageShim","correct":"const StorageShim = require('node-storage-shim')"},{"note":"TypeScript: use default type import for type-only usage; named import is incorrect.","wrong":"import { StorageShim } from 'node-storage-shim'","symbol":"StorageShim","correct":"import type StorageShim from 'node-storage-shim'"}],"quickstart":{"code":"// Node.js v6.14.4+ with CommonJS\nconst StorageShim = require('node-storage-shim');\nconst storage = new StorageShim();\nstorage.setItem('key', 'value');\nconsole.log(storage.getItem('key')); // 'value'\nconsole.log(storage.length); // 1\nstorage.removeItem('key');\nconsole.log(storage.length); // 0\n\n// Polyfill globals (for Node.js)\nglobal.localStorage = new StorageShim();\nglobal.sessionStorage = new StorageShim();","lang":"javascript","description":"Shows creation of a StorageShim instance, basic set/get/remove operations, and polyfilling localStorage/sessionStorage in Node.js."},"warnings":[{"fix":"Upgrade Node to >=6.14.4 and test code that iterates over storage keys or directly accesses properties.","message":"Version 2.0.0 dropped support for Node < 6.14.4 and introduced Proxy for direct property access, which may break code that relied on enumerable keys or the old storage behavior.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Avoid using keys that conflict with Storage interface method names.","message":"Method names (e.g., 'setItem', 'getItem') cannot be used as keys due to internal implementation using Proxy. This is a known limitation.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Manually mock the storage event or use a different shim that supports it.","message":"Does not implement the 'storage' event. If your code relies on storage event listeners, this shim will not trigger them.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Do not use for production persistence; use a real localStorage/sessionStorage or a persistent store instead.","message":"Data is not persisted to disk. It is solely in-memory and will be lost on process exit. This is by design for testing.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure tsconfig includes node_modules types. Import using default import syntax.","message":"TypeScript declaration is provided, but the package does not ship a separate .d.ts file; it is bundled via 'types' field in package.json.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'2020':30 'access':45 'allow':42 'api':50 'data':55 'declar':67 'direct':43 'disk':57 'environ':23 'event':64 'implement':9,61 'in-memori':6 'includ':68 'interfac':14 'javascript':69 'latest':33 'lightweight':65 'localstorage/sessionstorage':15 'maintain':47 'march':29 'memori':8 'node':2 'node-storage-shim':1 'node.js':22 'persist':54 'primarili':24 'properti':44 'proxi':38 'releas':35 'shim':4,20 'sinc':39 'stabl':34 'storag':3,13,49,63 'test':27 'typescript':66,70 'unit':26 'use':17,37 'v2.0.0':40 'v2.0.1':28 'w3c':12","created_at":"2026-06-07T16:58:25.056273+00:00","updated_at":"2026-06-07T16:58:25.056273+00:00","problems":[{"fix":"Run `npm install node-storage-shim --save-dev` or check the import statement.","cause":"Package not installed or import path typo.","error":"Cannot find module 'node-storage-shim'"},{"fix":"Use `const StorageShim = require('node-storage-shim')` in CommonJS or `import StorageShim from 'node-storage-shim'` in ESM.","cause":"Incorrect import: using named destructuring when default export is expected.","error":"TypeError: StorageShim is not a constructor"},{"fix":"Always use `new StorageShim()` to create an instance.","cause":"StorageShim constructor was called without 'new' or the instance was overwritten.","error":"TypeError: storage.getItem is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/mnahkies/node-storage-shim#readme","github":"https://github.com/mnahkies/node-storage-shim","docs":null,"changelog":null,"pypi":null,"npm":"node-storage-shim","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}