Skip to content
Finds the common standard cache directory
Branch: master
Clone or download
Latest commit da06f09 May 31, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig ES2015ify and require Node.js 4 May 12, 2017
.gitattributes Meta tweaks Jun 18, 2018
.gitignore Meta tweaks Jun 18, 2018
.npmrc Meta tweaks Jun 18, 2018
.travis.yml Update dependencies, require Node.js 8 (#15) Apr 9, 2019
index.js Meta tweaks Mar 12, 2019
license Meta tweaks Jun 18, 2018
package.json Tidelift tasks May 31, 2019

find-cache-dir Build Status Coverage Status

Finds the common standard cache directory

The nyc and AVA projects decided to standardize on a common directory structure for storing cache information:

# nyc

# ava

# your-module

This module makes it easy to correctly locate the cache directory according to this shared spec. If this pattern becomes ubiquitous, clearing the cache for multiple dependencies becomes easy and consistent:

rm -rf ./node_modules/.cache

If you decide to adopt this pattern, please file a PR adding your name to the list of adopters below.


$ npm install find-cache-dir


const findCacheDir = require('find-cache-dir');

findCacheDir({name: 'unicorns'});
//=> '/user/path/node-modules/.cache/unicorns'



Finds the cache directory using the supplied options. The algorithm tries to find a package.json file, searching every parent directory of the cwd specified (or implied from other options). It returns a string containing the absolute path to the cache directory, or undefined if package.json was never found.


Type: object


Type: string

Should be the same as your project name in package.json.


Type: string[] | string

An array of files that will be searched for a common parent directory. This common parent directory will be used in lieu of the cwd option below.


Type: string
Default process.cwd()

Directory to start searching for a package.json from.


Type: boolean
Default false

If true, the directory will be created synchronously before returning.


Type: boolean
Default false

If true, this modifies the return type to be a function that is a thunk for path.join(theFoundCacheDirectory).

const thunk = findCacheDir({name: 'foo', thunk: true});

//=> '/some/path/node_modules/.cache/foo'

//=> '/some/path/node_modules/.cache/foo/bar.js'

thunk('baz', 'quz.js')
//=> '/some/path/node_modules/.cache/foo/baz/quz.js'

This is helpful for actually putting actual files in the cache!


Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
You can’t perform that action at this time.