Registry / devops / app-cache-dir

app-cache-dir

JSON →
library0.4.0jsnpmunverified

app-cache-dir v0.4.0 resolves an application name to the standard cache directory path based on OS conventions: XDG_CACHE_HOME on POSIX, LOCALAPPDATA on Windows. Provides cross-platform cache paths (~/.cache/<app> on macOS/Linux, %LOCALAPPDATA%\<app>\cache on Windows). Includes .posix() and .win32() methods to force a specific platform layout. Falls back to os.tmpdir()/<app>/cache when environment variables are missing. Lightweight, no external dependencies, synchronous API. Last updated 2018, in maintenance mode.

npm install app-cache-dir
INSTALL
IMPORT
SIG · APP-CACHE-DIR
A
app-cache-dir
devopsjavascriptv0.4.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.

appCacheDir
const appCacheDir = require('app-cache-dir');
import appCacheDir from 'app-cache-dir';
CommonJS only; no ESM support. Use require().
appCacheDir.posix
const p = require('app-cache-dir').posix('my-app');
const { posix } = require('app-cache-dir'); posix('my-app');
posix and win32 are methods on the default export, not separate named exports.
appCacheDir.win32
const p = require('app-cache-dir').win32('my-app');
Same as posix; call as a method.

Shows basic usage, cross-platform behavior, forcing a specific platform, and XDG_CACHE_HOME override.

const appCacheDir = require('app-cache-dir'); const cachePath = appCacheDir('my-app'); console.log(cachePath); // e.g., '/home/user/.cache/my-app' or 'C:\Users\user\AppData\Local\my-app\cache' // Force POSIX behavior on any OS const posixPath = appCacheDir.posix('my-app'); console.log(posixPath); // '/home/user/.cache/my-app' // Force Windows behavior on any OS const winPath = appCacheDir.win32('my-app'); console.log(winPath); // 'C:\Users\user\AppData\Local\my-app\cache' // Respect environment variable process.env.XDG_CACHE_HOME = '/custom/cache'; const customPath = appCacheDir('my-app'); console.log(customPath); // '/custom/cache/my-app'
Debug
Known issues
breakingv0.3.0 changed the Windows path from %LOCALAPPDATA%\<app> to %LOCALAPPDATA%\<app>\cache or similar; check upgrade notes.
fix
Update any hardcoded Windows cache paths to include the \child directory if needed.
affects: >=0.3.0
deprecatedPackage last updated in 2018; no active development. Use at your own risk.
fix
Consider alternatives like env-paths or xdg-basedir for more modern support.
affects: all
gotchaOn POSIX, appCacheDir uses $XDG_CACHE_HOME if set, else $HOME/.cache. If both are empty (e.g., no home directory), it falls back to os.tmpdir()/<app>/cache.
fix
Ensure HOME or XDG_CACHE_HOME is set in production environments to avoid unexpected tmpdir usage.
affects: all
Errors
Common errors & fixes
Cannot find module 'app-cache-dir'
Package not installed or typo in require path.
fix
Run 'npm install app-cache-dir' and check the require statement: const appCacheDir = require('app-cache-dir');
TypeError: appCacheDir is not a function
Using default import in ESM context; the package only supports CommonJS.
fix
Use require('app-cache-dir') instead of import. If using ES modules, use createRequire or switch to a compatible package.
appCacheDir.posix is not a function
Trying to destructure posix as a named export.
fix
Call the method on the default export: const posixPath = require('app-cache-dir').posix('app');
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
app-cache-dir — npm install app-cache-dir · libregistry