Registry / storage / global-cache-dir

global-cache-dir

JSON →
library6.0.1jsnpmunverified

Get the global cache directory (OS-specific) and ensure it exists. Current version 6.0.1, with a stable release cadence via npm. Key differentiators: returns a normalized path using the OS-standard cache location (macOS: ~/Library/Caches, Linux: ~/.cache, Windows: AppData\Local\Cache), auto-creates the directory if missing, and is fully typed with TypeScript definitions. ESM-only, requires Node.js >=18.18.0. Simpler than alternatives like node-cachedir by providing a one-function API with directory creation.

npm install global-cache-dir
INSTALL
IMPORT
SIG · GLOBAL-CACHE-DIR
G
global-cache-dir
storagejavascriptv6.0.1
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 (globalCacheDir)
import globalCacheDir from 'global-cache-dir'
const globalCacheDir = require('global-cache-dir')
ESM-only since v6.0.0; do not use require().
globalCacheDir (named import mistakenly attempted)
import globalCacheDir from 'global-cache-dir'
import { globalCacheDir } from 'global-cache-dir'
This package has a default export only.
TypeScript type
import globalCacheDir from 'global-cache-dir'
type GlobalCacheDir = typeof import('global-cache-dir')
Types are included; no separate type import needed.

Gets and ensures the existence of the OS-specific global cache directory for 'myapp'.

import globalCacheDir from 'global-cache-dir'; const cacheDir = await globalCacheDir('myapp'); console.log(cacheDir); // macOS: /Users/username/Library/Caches/myapp // Linux: /home/username/.cache/myapp // Windows: C:\Users\username\AppData\Local\myapp\Cache
Debug
Known issues
breakingv6.0.0 dropped CommonJS support; only ESM is supported now.
fix
Switch to import syntax and ensure Node.js >=18.18.0.
affects: >=6.0.0
breakingv5.0.0 changed the return type from string to Promise<string>.
fix
Await the function call.
affects: >=5.0.0
gotchaThe name argument must only contain digits, letters, or dashes; otherwise the promise rejects.
fix
Sanitize input to [a-zA-Z0-9-]+.
affects: *
deprecatedv4.x and earlier used a synchronous function; now it's async.
fix
Upgrade to v5+ and use await.
affects: <5.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module /path/to/global-cache-dir/index.js from /path/to/project/index.js not supported.
Using CommonJS require() on an ESM-only package (v6+).
fix
Use import globalCacheDir from 'global-cache-dir' or downgrade to v4.x (but v4 is deprecated).
TypeError: Cannot read properties of undefined (reading 'then')
The return value from globalCacheDir() is a Promise, but was not awaited.
fix
Use await globalCacheDir('myapp') or .then().
Error: The 'name' argument must be a string. Received: undefined
Calling globalCacheDir() without arguments.
fix
Pass a valid name string.
Error: The 'name' argument must only use digits, letters or dashes. Received: 'my app'
Name contains spaces or invalid characters.
fix
Use only digits, letters, and dashes.
Upgrade
Version history
6.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

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