{"id":45614,"library":"npmd-cache","title":"npmd-cache","description":"A secure, reliable, offline-capable cache for npmd modules. Current stable version is 4.3.2. Provides an immutable content-addressable store for tarballs and a mutable database for module identifier to hash mappings. Supports offline install by caching modules from registry, GitHub, or arbitrary URLs. Differentiates from other caches by its content-addressable design and support for offline resolution via shasums.","status":"active","version":"4.3.2","language":"javascript","source_language":"en","source_url":"git://github.com/dominictarr/npmd-cache","tags":["javascript"],"install":[{"cmd":"npm install npmd-cache","lang":"bash","label":"npm"},{"cmd":"yarn add npmd-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add npmd-cache","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Persistent key-value store for mutable database","package":"level","optional":false},{"reason":"Log-structured database for immutable content store","package":"flumedb","optional":false},{"reason":"Continuation-based async utilities","package":"cont","optional":false}],"imports":[{"note":"Package provides a default export function. CommonJS require is also supported via module.exports.","wrong":"const cache = require('npmd-cache')","symbol":"npmd-cache","correct":"import cache from 'npmd-cache'"},{"note":"get is a method of the cache instance, not a static export.","wrong":"const get = require('npmd-cache').get; get(hash, cb)","symbol":"get","correct":"const { get } = cache; cache.get(hash, cb)"},{"note":"Requires a callback; no promise support by default.","wrong":"cache.put(url, tarball)","symbol":"put","correct":"cache.put(url, tarball, cb)"}],"quickstart":{"code":"const cache = require('npmd-cache')({ dir: '/tmp/my-cache' });\n\n// Get a module by hash\ncache.get('sha256-abc123...', (err, data) => {\n  if (err) console.error('Get error:', err);\n  else console.log('Module data length:', data.length);\n});\n\n// Put a tarball from URL\nconst tarball = Buffer.from('...'); // actual tarball buffer\ncache.put('https://registry.npmjs.org/foo/-/foo-1.0.0.tgz', tarball, (err, hash) => {\n  if (err) console.error('Put error:', err);\n  else console.log('Stored with hash:', hash);\n});\n\n// Resolve a module specifier to hash\ncache.resolve('foo@1.0.0', (err, hash) => {\n  if (err) console.error('Resolve error:', err);\n  else console.log('Resolved hash:', hash);\n});","lang":"javascript","description":"Creates a cache instance, then demonstrates get, put, and resolve operations with callbacks."},"warnings":[{"fix":"Wrap methods with util.promisify or use a promise library like Bluebird's promisifyAll.","message":"All methods are callback-based; no Promise support. Must use callbacks or wrap with promisify.","severity":"gotcha","affected_versions":"<=4.3.2"},{"fix":"Ensure the directory exists before initializing cache, e.g., create with mkdirp.","message":"The cache directory must already exist or be creatable; no automatic directory creation.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Monitor release notes for resolve replacement.","message":"The resolve method may be deprecated in future versions in favor of using the registry cache directly.","severity":"deprecated","affected_versions":">=4.3.0"}],"env_vars":null,"search_vec":"'4.3.2':18 'address':24,58 'arbitrari':48 'cach':3,10,42,53 'capabl':9 'content':23,57 'content-address':22,56 'current':14 'databas':31 'design':59 'differenti':50 'github':46 'hash':36 'identifi':34 'immut':21 'instal':40 'javascript':67 'map':37 'modul':13,33,43 'mutabl':30 'npmd':2,12 'npmd-cach':1 'offlin':8,39,63 'offline-cap':7 'provid':19 'registri':45 'reliabl':6 'resolut':64 'secur':5 'shasum':66 'stabl':15 'store':25 'support':38,61 'tarbal':27 'url':49 'version':16 'via':65","created_at":"2026-06-07T12:55:52.619864+00:00","updated_at":"2026-06-07T12:55:52.619864+00:00","problems":[{"fix":"Invoke cache as a function: const cache = require('npmd-cache')({ dir: '/my-cache' });","cause":"Did not instantiate cache with options (e.g., { dir: '/path' })","error":"TypeError: cache.get is not a function"},{"fix":"Create the directory before using cache: mkdir -p /my-cache or use fs.mkdirSync with recursive option.","cause":"Cache directory does not exist","error":"Error: ENOENT: no such file or directory, open '...'"},{"fix":"Install level: npm install level","cause":"Missing runtime dependency 'level'","error":"Error: Cannot find module 'level'"}],"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/dominictarr/npmd-cache","github":"git://github.com/dominictarr/npmd-cache","docs":null,"changelog":null,"pypi":null,"npm":"npmd-cache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage","devops"],"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}}