Registry / devops / cache-path

cache-path

JSON →
library4.0.11jsnpmunverified

A drop-in alternative to find-cache-dir that returns a cache directory path in any environment, even outside a module/package folder. Version 4.0.11, maintained in a monorepo with TypeScript types included. Key differentiators: (1) never fails when not inside a module/package, (2) customizable priority order for cache path discovery, (3) async API available. Supports both ESM and CommonJS, with normalized name generation for scoped packages.

npm install cache-path
INSTALL
IMPORT
SIG · CACHE-PATH
C
cache-path
devopsjavascriptv4.0.11
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.

getCachePath
import { getCachePath } from 'cache-path'
import getCachePath from 'cache-path'
This is a named export, not a default export.
normalizeName
import { normalizeName } from 'cache-path'
const normalizeName = require('cache-path').normalizeName
CJS require works but ESM import is preferred.
getCachePathAsync
import { getCachePathAsync } from 'cache-path'
Async version of getCachePath; available since v4.

Demonstrates basic usage of normalizeName and getCachePath sync/async, including scoped package normalization.

import { normalizeName, getCachePath } from 'cache-path'; console.log(normalizeName('@node-novel/sort')); // => _node_novel_sort console.log(normalizeName('@node-novel/sort', true)); // => 7bc015f2 console.log(getCachePath()); // => e.g., /home/user/.cache/npm/.cache console.log(getCachePath('@node-novel/sort')); // => /home/user/.cache/npm/.cache/_node_novel_sort // async version import { getCachePathAsync } from 'cache-path'; const path = await getCachePathAsync('my-app'); console.log(path);
Debug
Known issues
breakingFrom version 2 to 3, the default export was removed; all exports are now named.
fix
Change import { getCachePath } from 'cache-path' instead of import cachePath from 'cache-path'.
affects: >=2.0.0 <3.0.0
deprecatedThe sync function getCachePath is still available but consider using getCachePathAsync for non-blocking behavior.
fix
Use getCachePathAsync if async I/O acceptable.
affects: *
gotchaThe package uses a custom priority order for cache directories; if no cache directory found, it may return a fallback like /tmp. This differs from find-cache-dir which throws.
fix
Check if the returned path is writable before using.
affects: *
Errors
Common errors & fixes
Cannot find module 'cache-path'
Package not installed or import path incorrect.
fix
Run 'npm install cache-path' and ensure import uses named export.
cache-path_1.getCachePath is not a function
Using default import instead of named import.
fix
Change to import { getCachePath } from 'cache-path'.
NormalizeName is not defined
Typo in function name (capital N).
fix
Use normalizeName (lowercase n).
Upgrade
Version history
4.0.11latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
cache-path — npm install cache-path · libregistry