Get paths for storing things like data, config, cache, etc
Uses the correct OS-specific paths. Most developers get this wrong.
Install
npm install env-paths
Usage
import envPaths from 'env-paths';const paths = envPaths('MyApp');paths.data;//=> '/home/sindresorhus/.local/share/MyApp-nodejs'paths.config//=> '/home/sindresorhus/.config/MyApp-nodejs'
API
paths = envPaths(name, options?)
Note: It only generates the path strings. It doesn't create the directories for you. You can use fs.mkdir(…, {recursive: true}) to create the directories.
name
Type: string
The name of your project. Used to generate the paths.
options
Type: object
suffix
Type: string
Default: 'nodejs'
Don't use this option unless you really have to!
Suffix appended to the project name to avoid name conflicts with native apps. Pass an empty string to disable it.
paths.data
Directory for data files.
Example locations (with the default nodejssuffix):
macOS: ~/Library/Application Support/MyApp-nodejs
Windows: %LOCALAPPDATA%\MyApp-nodejs\Data (for example, C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Data)