Registry / storage / cache-or-tmp-directory

cache-or-tmp-directory

JSON →
library1.0.0jsnpmunverified

Returns the system cache directory for a given app name, or falls back to a predictable temporary directory. Version 1.0.0 is stable with no known release cadence. Alternatives like 'cache-directory' require optional dependencies (e.g., osx-tmpdir) and may fail entirely; this package always returns a writable path. It does not create the directory, only provides the path. The temp fallback is non-random, allowing cache sharing across processes. Lightweight, no dependencies, supports Node.js only.

npm install cache-or-tmp-directory
INSTALL
IMPORT
SIG · CACHE-OR-TMP-DIREC
C
cache-or-tmp-directory
storagejavascriptv1.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.

cacheOrTmpDir
import cacheOrTmpDir from 'cache-or-tmp-directory'
const cacheOrTmpDir = require('cache-or-tmp-directory').default
Package is ESM-only as of v1; default export via require() works directly, but .default is a common mistake.
default export
const cacheOrTmpDir = require('cache-or-tmp-directory')
const { cacheOrTmpDir } = require('cache-or-tmp-directory')
CommonJS require returns the function directly, not an object with named exports.
cacheOrTmpDir type (TypeScript)
import cacheOrTmpDir from 'cache-or-tmp-directory'
import * as cacheOrTmpDir from 'cache-or-tmp-directory'
Package does not ship TypeScript types; use @types/node or declare module. Namespace import is unnecessary.

Gets the cache directory for 'myApp' and shows how to create it (package does not create directories).

import cacheOrTmpDir from 'cache-or-tmp-directory'; const appName = 'myApp'; const dir = cacheOrTmpDir(appName); console.log(`Cache directory: ${dir}`); // Note: directory is not created; you must create it yourself: import { mkdirSync } from 'fs'; mkdirSync(dir, { recursive: true });
Debug
Known issues
gotchaPackage does not create the directory; it only returns a path. You must create it yourself.
fix
Use fs.mkdirSync(dir, { recursive: true }) after getting the path.
affects: >=1.0
gotchaTemporary fallback path has no random component; it may collide with other processes using the same app name.
fix
If you need unique temp directories, use a library like tmp or add randomness manually.
affects: >=1.0
breakingPackage is ESM-only since v1.0.0; CommonJS require may still work, but dynamic imports are encouraged.
fix
Use import or dynamic import() instead of require.
affects: >=1.0
gotchaOn some Linux systems, XDG_CACHE_HOME may not be set, causing fallback to ~/.cache.
fix
Set XDG_CACHE_HOME environment variable explicitly if needed.
affects: >=1.0
Errors
Common errors & fixes
TypeError: cacheOrTmpDir is not a function
Using named import instead of default import (e.g., import { cacheOrTmpDir } from ...)
fix
import cacheOrTmpDir from 'cache-or-tmp-directory'
Error: ENOENT: no such file or directory, mkdir '/path/to/cache'
Assuming the package creates the directory; it only returns a path.
fix
Manually create the directory with fs.mkdirSync(dir, { recursive: true }).
Module not found: Default condition should be last, got one from package.json
Using an older bundler (e.g., webpack 4) that doesn't support ESM conditional exports properly.
fix
Upgrade to webpack 5 or use a bundler that supports package.json exports.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
17
OpenAI (training)
1
Resources
cache-or-tmp-directory — npm install cache-or-tmp-directory · libregistry