Registry / devops / npm-cache-env

npm-cache-env

JSON →
library2.0.0jsnpmunverified

Small utility (v2.0.0, 2018) to retrieve the npm cache folder path from environment variables (e.g., npm_config_cache). Case-insensitive lookup of npm config environment variables; returns null if not set. Always resolves relative paths to absolute. No dependencies. Good for tooling that needs to locate npm cache without invoking npm CLI. Last release stable; no recent updates.

npm install npm-cache-env
INSTALL
IMPORT
SIG · NPM-CACHE-ENV
N
npm-cache-env
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.

npmCacheEnv
const npmCacheEnv = require('npm-cache-env');
import npmCacheEnv from 'npm-cache-env';
CJS only — no ESM or default export; named export does not exist.
npmCacheEnv()
npmCacheEnv();
npmCacheEnv;
Function call required; returns string or null.
require('npm-cache-env')
const npmCacheEnv = require('npm-cache-env');
const { npmCacheEnv } = require('npm-cache-env');
Not a named export; the module exports the function directly.

Retrieve npm cache directory from environment variables using npm-cache-env.

const npmCacheEnv = require('npm-cache-env'); // If NPM_CONFIG_CACHE=/foo/bar is set in environment: npmCacheEnv(); //=> '/foo/bar' // If not set: npmCacheEnv(); //=> null // Relative paths are resolved to absolute: // With npm_config_cache=./cache set: npmCacheEnv(); //=> '/current/working/dir/cache'
Debug
Known issues
gotchaModule is CJS only; ESM import (import npmCacheEnv from 'npm-cache-env') will fail.
fix
Use require() or ensure bundler conversion.
affects: >=0.0.0
deprecatedPackage hasn't been updated since 2018; npm config environment variable behavior may change in future npm versions.
fix
Check compatibility, consider using @npmcli/config or reading .npmrc directly.
affects: >=0.0.0
gotchaThe function always returns a string or null; never undefined.
fix
Handle null explicitly.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: npmCacheEnv is not a function
Importing the module incorrectly (e.g., destructuring or default import).
fix
Use const npmCacheEnv = require('npm-cache-env'); without destructuring.
Cannot find module 'npm-cache-env'
Package not installed or missing from node_modules.
fix
Run npm install npm-cache-env.
Expected a string but got null
Environment variable not set; function returns null.
fix
Set the npm_config_cache environment variable or handle null fallback.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
npm-cache-env — npm install npm-cache-env · libregistry