# global-cache-dir

> Get the global cache directory

Latest version **6.0.1** (published 2025-03-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install global-cache-dir
pnpm add global-cache-dir
yarn add global-cache-dir
bun add global-cache-dir
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.0.1 |
| Published | 2025-03-29 |
| First published | 2019-08-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.18.0 |
| Dependencies | 2 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | ehmicky |
| Maintainers | ehmicky |
| Keywords | cache, caching, directory, filesystem, operating-system, global, performance, files, path, javascript, typescript, es6, library, windows, mac, macos, linux, bsd, android, nodejs |

## Links

- npm: https://www.npmjs.com/package/global-cache-dir
- Repository: https://github.com/ehmicky/global-cache-dir
- Homepage: https://www.github.com/ehmicky/global-cache-dir
- Issues: https://github.com/ehmicky/global-cache-dir/issues
- npm.io page: https://npm.io/package/global-cache-dir

## Dependencies (2)

- [cachedir](https://npm.io/package/cachedir.md) ^2.4.0
- [path-exists](https://npm.io/package/path-exists.md) ^5.0.0

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 6.0.1 (latest) — 2025-03-29
- 6.0.0 — 2023-10-28
- 5.0.0 — 2023-05-13
- 4.4.0 — 2022-11-11
- 4.3.1 — 2022-10-13
- 4.3.0 — 2022-10-13
- 4.2.0 — 2022-08-16
- 4.1.0 — 2022-06-26
- 4.0.0 — 2022-05-09
- 3.0.1 — 2021-06-22
- 3.0.0 — 2021-06-22
- 2.0.0 — 2019-12-25
- 1.0.1 — 2019-10-16
- 1.0.0 — 2019-08-09
- 0.0.3 — 2019-08-09
- … 1 more at https://npm.io/package/global-cache-dir/versions

## README

[![Node](https://img.shields.io/badge/-Node.js-808080?logo=node.js&colorA=404040&logoColor=66cc33)](https://www.npmjs.com/package/global-cache-dir)
[![TypeScript](https://img.shields.io/badge/-Typed-808080?logo=typescript&colorA=404040&logoColor=0096ff)](/src/main.d.ts)
[![Codecov](https://img.shields.io/badge/-Tested%20100%25-808080?logo=codecov&colorA=404040)](https://codecov.io/gh/ehmicky/global-cache-dir)
[![Mastodon](https://img.shields.io/badge/-Mastodon-808080.svg?logo=mastodon&colorA=404040&logoColor=9590F9)](https://fosstodon.org/@ehmicky)
[![Medium](https://img.shields.io/badge/-Medium-808080.svg?logo=medium&colorA=404040)](https://medium.com/@ehmicky)

Get the global cache directory.

Ensures the directory exists.

The cache directory location is OS-specific.

# Example

```js
import globalCacheDir from 'global-cache-dir'

const cacheDir = await globalCacheDir('myapp')
// Depending on the OS:
//  => '/Users/ehmicky/Library/Caches/myapp'
//  => '/home/ehmicky/.cache/myapp'
//  => 'C:\Users\ehmicky\AppData\Local\myapp\Cache'
```

# Install

```bash
npm install global-cache-dir
```

This package works in Node.js >=18.18.0.

This is an ES module. It must be loaded using
[an `import` or `import()` statement](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c),
not `require()`. If TypeScript is used, it must be configured to
[output ES modules](https://www.typescriptlang.org/docs/handbook/esm-node.html),
not CommonJS.

# Usage

## globalCacheDir(name)

`name`: `string`\
_Returns_: `Promise<string>`

`name` must only use digits, letters or dashes.

# See also

- [`node-cachedir`](https://github.com/LinusU/node-cachedir): underlying logic
  for this module
- [`find-cache-dir`](https://github.com/avajs/find-cache-dir): get the local
  cache directory

# Support

For any question, _don't hesitate_ to [submit an issue on GitHub](../../issues).

Everyone is welcome regardless of personal background. We enforce a
[Code of conduct](CODE_OF_CONDUCT.md) in order to promote a positive and
inclusive environment.

# Contributing

This project was made with ❤️. The simplest way to give back is by starring and
sharing it online.

If the documentation is unclear or has a typo, please click on the page's `Edit`
button (pencil icon) and suggest a correction.

If you would like to help us fix a bug or add a new feature, please check our
[guidelines](CONTRIBUTING.md). Pull requests are welcome!

<!-- Thanks go to our wonderful contributors: -->

<!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore -->
<!--
<table><tr><td align="center"><a href="https://fosstodon.org/@ehmicky"><img src="https://avatars2.githubusercontent.com/u/8136211?v=4" width="100px;" alt="ehmicky"/><br /><sub><b>ehmicky</b></sub></a><br /><a href="https://github.com/ehmicky/global-cache-dir/commits?author=ehmicky" title="Code">💻</a> <a href="#design-ehmicky" title="Design">🎨</a> <a href="#ideas-ehmicky" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ehmicky/global-cache-dir/commits?author=ehmicky" title="Documentation">📖</a></td></tr></table>
-->
<!-- ALL-CONTRIBUTORS-LIST:END -->

---
_Source: https://npm.io/package/global-cache-dir · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
