Package Exports
- npm-cache-env
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (npm-cache-env) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
npm-cache-env
Get the path of npm cache folder from environment variables
// NPM_CONFIG_CACHE=/foo/bar node ./example.js
const npmCacheEnv = require('npm-cache-env');
npmCacheEnv(); //=> '/foo/bar'
Installation
npm install npm-cache-env
API
const npmCacheEnv = require('npm-cache-env');
npmCacheEnv()
Return: String
or null
It finds an environment variable corresponding to the cache
config of npm
CLI:
https://docs.npmjs.com/misc/config#environment-variables
Any environment variables that start with
npm_config_
will be interpreted as a configuration parameter. For example, puttingnpm_config_foo=bar
in your environment will set thefoo
configuration parameter tobar
.
If the cache
config parameter doesn't exist in the environment variables, it returns null
.
const npmCacheEnv = require('npm-cache-env');
// Npm_Config_Cache=/User/shinnn node ./example.js
npmCacheEnv(); //=> '/User/shinnn'
// node ./example.js
npmCacheEnv(); //=> null
The resultant path always becomes absolute.
const npmCacheEnv = require('npm-cache-env');
// npm_config_cache=123 node ./example.js
npmCacheEnv(); //=> '/path/to/current/working/directory/123'