appdirsjs
A lightweight Node.js library providing standardized paths for directories to store configs, caches, and data files according to OS standards. On Linux, it follows the XDG Base Directory Specification. On macOS and Windows, it follows Apple and Microsoft guidelines.
Installation
Using npm:
npm install appdirsjs
Or if you use Yarn:
yarn add appdirsjs
Usage
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
Keep backward compatibility
When switching from an old-style dotfile directory,
such as ~/.myapp, to a new one, like ~/.config/myapp,
you can pass the legacyPath parameter
to keep using the 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
TODO
- Android support
- XDG on BSD support
- CI tests on
bunanddeno - Dev dependencies update
- README.md cleanup