[6a3a178] | 1 | # env-paths
|
---|
| 2 |
|
---|
| 3 | > Get paths for storing things like data, config, cache, etc
|
---|
| 4 |
|
---|
| 5 | Uses the correct OS-specific paths. Most developers get this wrong.
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | ## Install
|
---|
| 9 |
|
---|
| 10 | ```
|
---|
| 11 | $ npm install env-paths
|
---|
| 12 | ```
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | ## Usage
|
---|
| 16 |
|
---|
| 17 | ```js
|
---|
| 18 | const envPaths = require('env-paths');
|
---|
| 19 |
|
---|
| 20 | const paths = envPaths('MyApp');
|
---|
| 21 |
|
---|
| 22 | paths.data;
|
---|
| 23 | //=> '/home/sindresorhus/.local/share/MyApp-nodejs'
|
---|
| 24 |
|
---|
| 25 | paths.config
|
---|
| 26 | //=> '/home/sindresorhus/.config/MyApp-nodejs'
|
---|
| 27 | ```
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | ## API
|
---|
| 31 |
|
---|
| 32 | ### paths = envPaths(name, options?)
|
---|
| 33 |
|
---|
| 34 | Note: It only generates the path strings. It doesn't create the directories for you. You could use [`make-dir`](https://github.com/sindresorhus/make-dir) to create the directories.
|
---|
| 35 |
|
---|
| 36 | #### name
|
---|
| 37 |
|
---|
| 38 | Type: `string`
|
---|
| 39 |
|
---|
| 40 | Name of your project. Used to generate the paths.
|
---|
| 41 |
|
---|
| 42 | #### options
|
---|
| 43 |
|
---|
| 44 | Type: `object`
|
---|
| 45 |
|
---|
| 46 | ##### suffix
|
---|
| 47 |
|
---|
| 48 | Type: `string`<br>
|
---|
| 49 | Default: `'nodejs'`
|
---|
| 50 |
|
---|
| 51 | **Don't use this option unless you really have to!**<br>
|
---|
| 52 | Suffix appended to the project name to avoid name conflicts with native
|
---|
| 53 | apps. Pass an empty string to disable it.
|
---|
| 54 |
|
---|
| 55 | ### paths.data
|
---|
| 56 |
|
---|
| 57 | Directory for data files.
|
---|
| 58 |
|
---|
| 59 | Example locations (with the default `nodejs` [suffix](#suffix)):
|
---|
| 60 |
|
---|
| 61 | - macOS: `~/Library/Application Support/MyApp-nodejs`
|
---|
| 62 | - Windows: `%LOCALAPPDATA%\MyApp-nodejs\Data` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Data`)
|
---|
| 63 | - Linux: `~/.local/share/MyApp-nodejs` (or `$XDG_DATA_HOME/MyApp-nodejs`)
|
---|
| 64 |
|
---|
| 65 | ### paths.config
|
---|
| 66 |
|
---|
| 67 | Directory for config files.
|
---|
| 68 |
|
---|
| 69 | Example locations (with the default `nodejs` [suffix](#suffix)):
|
---|
| 70 |
|
---|
| 71 | - macOS: `~/Library/Preferences/MyApp-nodejs`
|
---|
| 72 | - Windows: `%APPDATA%\MyApp-nodejs\Config` (for example, `C:\Users\USERNAME\AppData\Roaming\MyApp-nodejs\Config`)
|
---|
| 73 | - Linux: `~/.config/MyApp-nodejs` (or `$XDG_CONFIG_HOME/MyApp-nodejs`)
|
---|
| 74 |
|
---|
| 75 | ### paths.cache
|
---|
| 76 |
|
---|
| 77 | Directory for non-essential data files.
|
---|
| 78 |
|
---|
| 79 | Example locations (with the default `nodejs` [suffix](#suffix)):
|
---|
| 80 |
|
---|
| 81 | - macOS: `~/Library/Caches/MyApp-nodejs`
|
---|
| 82 | - Windows: `%LOCALAPPDATA%\MyApp-nodejs\Cache` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Cache`)
|
---|
| 83 | - Linux: `~/.cache/MyApp-nodejs` (or `$XDG_CACHE_HOME/MyApp-nodejs`)
|
---|
| 84 |
|
---|
| 85 | ### paths.log
|
---|
| 86 |
|
---|
| 87 | Directory for log files.
|
---|
| 88 |
|
---|
| 89 | Example locations (with the default `nodejs` [suffix](#suffix)):
|
---|
| 90 |
|
---|
| 91 | - macOS: `~/Library/Logs/MyApp-nodejs`
|
---|
| 92 | - Windows: `%LOCALAPPDATA%\MyApp-nodejs\Log` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Log`)
|
---|
| 93 | - Linux: `~/.local/state/MyApp-nodejs` (or `$XDG_STATE_HOME/MyApp-nodejs`)
|
---|
| 94 |
|
---|
| 95 | ### paths.temp
|
---|
| 96 |
|
---|
| 97 | Directory for temporary files.
|
---|
| 98 |
|
---|
| 99 | Example locations (with the default `nodejs` [suffix](#suffix)):
|
---|
| 100 |
|
---|
| 101 | - macOS: `/var/folders/jf/f2twvvvs5jl_m49tf034ffpw0000gn/T/MyApp-nodejs`
|
---|
| 102 | - Windows: `%LOCALAPPDATA%\Temp\MyApp-nodejs` (for example, `C:\Users\USERNAME\AppData\Local\Temp\MyApp-nodejs`)
|
---|
| 103 | - Linux: `/tmp/USERNAME/MyApp-nodejs`
|
---|
| 104 |
|
---|
| 105 | ---
|
---|
| 106 |
|
---|
| 107 | <div align="center">
|
---|
| 108 | <b>
|
---|
| 109 | <a href="https://tidelift.com/subscription/pkg/npm-env-paths?utm_source=npm-env-paths&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
---|
| 110 | </b>
|
---|
| 111 | <br>
|
---|
| 112 | <sub>
|
---|
| 113 | Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
---|
| 114 | </sub>
|
---|
| 115 | </div>
|
---|