# xdg-basedir

> Get XDG Base Directory paths

Latest version **5.1.0** (published 2021-08-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install xdg-basedir
pnpm add xdg-basedir
yarn add xdg-basedir
bun add xdg-basedir
```

## Health

**Score 28/100 (F)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.1.0 |
| Published | 2021-08-05 |
| First published | 2014-10-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/xdg-basedir) |
| Module format | ESM |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 94 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | xdg, base, directory, basedir, path, data, config, cache, linux, unix, spec |

## Links

- npm: https://www.npmjs.com/package/xdg-basedir
- Repository: https://github.com/sindresorhus/xdg-basedir
- Homepage: https://github.com/sindresorhus/xdg-basedir#readme
- Issues: https://github.com/sindresorhus/xdg-basedir/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/xdg-basedir

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 5.1.0 (latest) — 2021-08-05
- 5.0.1 — 2021-04-05
- 5.0.0 — 2021-04-05
- 4.0.0 — 2019-04-30
- 3.0.0 — 2017-02-13
- 2.0.0 — 2015-06-13
- 1.0.1 — 2015-01-13
- 1.0.0 — 2014-10-06

## README

# xdg-basedir

> Get [XDG Base Directory](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) paths

This package is meant for Linux. You should not use XDG on macOS or Windows. Instead, you should follow their platform conventions. You can use [`env-paths`](https://github.com/sindresorhus/env-paths) for that.

## Install

```
$ npm install xdg-basedir
```

## Usage

```js
import {xdgData, xdgConfig, xdgDataDirectories} from 'xdg-basedir';

console.log(xdgData);
//=> '/home/sindresorhus/.local/share'

console.log(xdgConfig);
//=> '/home/sindresorhus/.config'

console.log(xdgDataDirectories);
//=> ['/home/sindresorhus/.local/share', '/usr/local/share/', '/usr/share/']
```

## API

The exports `xdgData`, `xdgConfig`, `xdgCache`, `xdgRuntime` will return `undefined` in the uncommon case that both the XDG environment variable is not set and the users home directory can't be found. You need to handle this case. A common solution is to [fall back to a temporary directory](https://github.com/yeoman/configstore/blob/b82690fc401318ad18dcd7d151a0003a4898a314/index.js#L15).

### xdgData

Directory for user-specific data files.

### xdgConfig

Directory for user-specific configuration files.

### xdgState

Directory for user-specific state files.

### xdgCache

Directory for user-specific non-essential data files.

### xdgRuntime

Directory for user-specific non-essential runtime files and other file objects (such as sockets, named pipes, etc).

### xdgDataDirectories

Preference-ordered array of base directories to search for data files in addition to `xdgData`.

### xdgConfigDirectories

Preference-ordered array of base directories to search for configuration files in addition to `xdgConfig`.

---

<div align="center">
	<b>
		<a href="https://tidelift.com/subscription/pkg/npm-xdg-basedir?utm_source=npm-xdg-basedir&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
	</b>
	<br>
	<sub>
		Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
	</sub>
</div>

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