{"id":44494,"library":"cache-or-tmp-directory","title":"cache-or-tmp-directory","description":"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.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/strugee/node-cache-or-tmp-directory","tags":["javascript","cache","directory","temporary","caching"],"install":[{"cmd":"npm install cache-or-tmp-directory","lang":"bash","label":"npm"},{"cmd":"yarn add cache-or-tmp-directory","lang":"bash","label":"yarn"},{"cmd":"pnpm add cache-or-tmp-directory","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is ESM-only as of v1; default export via require() works directly, but .default is a common mistake.","wrong":"const cacheOrTmpDir = require('cache-or-tmp-directory').default","symbol":"cacheOrTmpDir","correct":"import cacheOrTmpDir from 'cache-or-tmp-directory'"},{"note":"CommonJS require returns the function directly, not an object with named exports.","wrong":"const { cacheOrTmpDir } = require('cache-or-tmp-directory')","symbol":"default export","correct":"const cacheOrTmpDir = require('cache-or-tmp-directory')"},{"note":"Package does not ship TypeScript types; use @types/node or declare module. Namespace import is unnecessary.","wrong":"import * as cacheOrTmpDir from 'cache-or-tmp-directory'","symbol":"cacheOrTmpDir type (TypeScript)","correct":"import cacheOrTmpDir from 'cache-or-tmp-directory'"}],"quickstart":{"code":"import cacheOrTmpDir from 'cache-or-tmp-directory';\n\nconst appName = 'myApp';\nconst dir = cacheOrTmpDir(appName);\n\nconsole.log(`Cache directory: ${dir}`);\n\n// Note: directory is not created; you must create it yourself:\nimport { mkdirSync } from 'fs';\nmkdirSync(dir, { recursive: true });","lang":"typescript","description":"Gets the cache directory for 'myApp' and shows how to create it (package does not create directories)."},"warnings":[{"fix":"Use fs.mkdirSync(dir, { recursive: true }) after getting the path.","message":"Package does not create the directory; it only returns a path. You must create it yourself.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"If you need unique temp directories, use a library like tmp or add randomness manually.","message":"Temporary fallback path has no random component; it may collide with other processes using the same app name.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Use import or dynamic import() instead of require.","message":"Package is ESM-only since v1.0.0; CommonJS require may still work, but dynamic imports are encouraged.","severity":"breaking","affected_versions":">=1.0"},{"fix":"Set XDG_CACHE_HOME environment variable explicitly if needed.","message":"On some Linux systems, XDG_CACHE_HOME may not be set, causing fallback to ~/.cache.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"search_vec":"'1.0.0':25 'across':76 'allow':73 'altern':33 'alway':51 'app':14 'back':18 'cach':2,9,36,74,85,88 'cache-directori':35 'cache-or-tmp-directori':1 'cadenc':32 'creat':59 'depend':40,80 'directori':5,10,23,37,61,86 'e.g':41 'entir':48 'fail':47 'fall':17 'fallback':68 'given':13 'javascript':84 'known':30 'lightweight':78 'like':34 'may':46 'name':15 'node.js':82 'non':71 'non-random':70 'option':39 'osx':43 'osx-tmpdir':42 'packag':50 'path':55,65 'predict':21 'process':77 'provid':63 'random':72 'releas':31 'requir':38 'return':6,52 'share':75 'stabl':27 'support':81 'system':8 'temp':67 'temporari':22,87 'tmp':4 'tmpdir':44 'version':24 'writabl':54","created_at":"2026-06-07T12:50:24.304807+00:00","updated_at":"2026-06-07T12:50:24.304807+00:00","problems":[{"fix":"import cacheOrTmpDir from 'cache-or-tmp-directory'","cause":"Using named import instead of default import (e.g., import { cacheOrTmpDir } from ...)","error":"TypeError: cacheOrTmpDir is not a function"},{"fix":"Manually create the directory with fs.mkdirSync(dir, { recursive: true }).","cause":"Assuming the package creates the directory; it only returns a path.","error":"Error: ENOENT: no such file or directory, mkdir '/path/to/cache'"},{"fix":"Upgrade to webpack 5 or use a bundler that supports package.json exports.","cause":"Using an older bundler (e.g., webpack 4) that doesn't support ESM conditional exports properly.","error":"Module not found: Default condition should be last, got one from package.json"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/strugee/node-cache-or-tmp-directory#readme","github":"https://github.com/strugee/node-cache-or-tmp-directory","docs":null,"changelog":null,"pypi":null,"npm":"cache-or-tmp-directory","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}