Registry / devops / cache-directory

cache-directory

JSON →
library2.0.0jsnpmunverified

A lightweight utility (v2.0.0, last updated ~2017) to determine the correct OS-specific cache directory (XDG on Linux, ~/Library/Caches on macOS, LocalAppData on Windows). Minimal API with one synchronous function. Unlike xdg-based-cache or find-cache-dir, this module has no dependencies and works on older Node.js (>=4). Released under LGPL 3.0+.

npm install cache-directory
INSTALL
IMPORT
SIG · CACHE-DIRECTORY
C
cache-directory
devopsjavascriptv2.0.0
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.

default
✓ import cacheDirectory from 'cache-directory'
✗ const cacheDirectory = require('cache-directory')
Package is CommonJS. The default export is a function. In ESM environments, use default import or dynamic import().
cacheDirectory
✓ const cacheDirectory = require('cache-directory');
Standard CommonJS usage.

Shows how to get the OS-specific cache directory for an app name and handle the null case.

const cacheDirectory = require('cache-directory'); const dir = cacheDirectory('myApp'); if (dir !== null) { console.log('Cache directory:', dir); } else { console.log('Could not determine cache directory, using temp dir'); // fallback }
Debug
Known issues
gotchaFunction returns null if no suitable cache directory is found. Must handle this fallback.
fix
Check for null and use a temp directory (e.g., os.tmpdir()) as fallback.
affects: >=0.0.0
gotchaOn macOS, assumes non-sandboxed environment; in sandboxed processes the path may be wrong.
fix
Use process.env.HOME or other sandbox-aware method for sandboxed apps.
affects: >=0.0.0
gotchaOn macOS, uses app name directly instead of the conventional bundle identifier.
fix
Pass the bundle identifier as the app name if stricter adherence to Apple conventions is needed.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'cache-directory'
Module not installed or typo in package name.
fix
Run 'npm install cache-directory' and ensure the import path is correct.
cacheDirectory is not a function
Wrong import style; e.g., destructuring or using wrong symbol.
fix
Use 'const cacheDirectory = require('cache-directory');' or import default.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
12
Resources
cache-directory — npm install cache-directory · libregistry