node-cache-directory

Find the proper cache directory based on operating system

LGPL-3.0 License

Downloads
102.3K
Stars
0
Committers
5

cache-directory

Find the proper cache directory based on operating system

Installation

npm install cache-directory

Usage

cache-directory takes one argument, the app name.

var cacheDir = require('cache-directory');

console.log(cacheDir('myApp'));

If you want, you can pass an optional options object to override the platform:

var cacheDir = require('cache-directory');

console.log(cacheDir('myApp', { platform: 'linux' }));

Caveats

cache-directory will not create the returned path for you; you need to do that yourself.

When run on macOS, cache-directory assumes it isn't run in a sandboxed process environment. If it is, it will probably break. Additionally, the app name is used instead of the conventional bundle identifier (for simplicity and because many cache-directory consumers won't necessarily have a bundle identifier).

If a suitable cache directory can't be found, cache-directory will return null. You need to handle this case. A reasonable course of action would be to use a temp directory, for which you can use the cache-or-tmp-directory module.

Supported platforms

  • Windows
  • macOS
  • Linux

License

LGPL 3.0+

Author

Alex Jordan [email protected]