New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

npm-cache-env

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-cache-env

Get the path of npm cache folder from environment variables

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

npm-cache-env

npm version Build Status Coverage Status

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

Use npm.

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, putting npm_config_foo=bar in your environment will set the foo configuration parameter to bar.

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'

License

ISC License © 2018 Shinnosuke Watanabe

Keywords

npm

FAQs

Package last updated on 06 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts