Registry / storage / npmd-cache

npmd-cache

JSON →
library4.3.2jsnpmunverified

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.

npm install npmd-cache
INSTALL
IMPORT
SIG · NPMD-CACHE
N
npmd-cache
storagejavascriptv4.3.2
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.

npmd-cache
✓ import cache from 'npmd-cache'
✗ const cache = require('npmd-cache')
Package provides a default export function. CommonJS require is also supported via module.exports.
get
✓ const { get } = cache; cache.get(hash, cb)
✗ const get = require('npmd-cache').get; get(hash, cb)
get is a method of the cache instance, not a static export.
put
✓ cache.put(url, tarball, cb)
✗ cache.put(url, tarball)
Requires a callback; no promise support by default.

Creates a cache instance, then demonstrates get, put, and resolve operations with callbacks.

const cache = require('npmd-cache')({ dir: '/tmp/my-cache' }); // Get a module by hash cache.get('sha256-abc123...', (err, data) => { if (err) console.error('Get error:', err); else console.log('Module data length:', data.length); }); // Put a tarball from URL const tarball = Buffer.from('...'); // actual tarball buffer cache.put('https://registry.npmjs.org/foo/-/foo-1.0.0.tgz', tarball, (err, hash) => { if (err) console.error('Put error:', err); else console.log('Stored with hash:', hash); }); // Resolve a module specifier to hash cache.resolve('foo@1.0.0', (err, hash) => { if (err) console.error('Resolve error:', err); else console.log('Resolved hash:', hash); });
Debug
Known issues
gotchaAll methods are callback-based; no Promise support. Must use callbacks or wrap with promisify.
fix
Wrap methods with util.promisify or use a promise library like Bluebird's promisifyAll.
affects: <=4.3.2
gotchaThe cache directory must already exist or be creatable; no automatic directory creation.
fix
Ensure the directory exists before initializing cache, e.g., create with mkdirp.
affects: >=4.0.0
deprecatedThe resolve method may be deprecated in future versions in favor of using the registry cache directly.
fix
Monitor release notes for resolve replacement.
affects: >=4.3.0
Errors
Common errors & fixes
TypeError: cache.get is not a function
Did not instantiate cache with options (e.g., { dir: '/path' })
fix
Invoke cache as a function: const cache = require('npmd-cache')({ dir: '/my-cache' });
Error: ENOENT: no such file or directory, open '...'
Cache directory does not exist
fix
Create the directory before using cache: mkdir -p /my-cache or use fs.mkdirSync with recursive option.
Error: Cannot find module 'level'
Missing runtime dependency 'level'
fix
Install level: npm install level
Upgrade
Version history
4.3.2latest on npm
Audit
Dependencies
levelrequiredPersistent key-value store for mutable database
flumedbrequiredLog-structured database for immutable content store
contrequiredContinuation-based async utilities
Agent activity
22 hits · last 30 days
node
22
Resources
npmd-cache — npm install npmd-cache · libregistry