A lightweight Node.js library providing standardized paths for directories to store configs, caches, and data files according to OS standards. On Linux it's following XDG Base Directory Specification. On MacOS and Windows it's following Apple and Microsoft guidelines.
Using npm:
npm install appdirsjs
Or if you use Yarn:
yarn install appdirsjs
import appDirs from "appdirsjs";
const dirs = appDirs({ appName: "expo" });
// Display the OS-specific cache directory for temporary files
console.log("Cache Directory:", dirs.cache);
// Linux: /home/user/.cache/expo
// macOS: /Users/User/Library/Caches/expo
// Windows: C:\Users\User\AppData\Local\Temp\expo
// Display the OS-specific configuration directory for user settings
console.log("Config Directory:", dirs.config);
// Linux: /home/user/.config/expo
// macOS: /Users/User/Library/Preferences/expo
// Windows: C:\Users\User\AppData\Roaming\expo
// Display the OS-specific data directory for application data
console.log("Data Directory:", dirs.data);
// Linux: /home/user/.local/share/expo
// macOS: /Users/User/Library/Application Support/expo
// Windows: C:\Users\User\AppData\Local\expo
Then switching from old-style dotfile directory,
such as ~/.myapp
to new, like ~/.config/myapp
,
you can pass legacyPath
parameter
to keep using old directory if it exists:
import * as os from "os";
import * as path from "path";
import appDirs from "appdirsjs";
const dirs = appDirs({
appName: "expo",
// Use legacy directory if it exists
legacyPath: path.join(os.homedir(), ".expo"),
});
console.log("Configuration Directory:", dirs.config);
// For instance, on Linux: /home/user/.expo
- Android support
- XDG on BSD support