Skip to content

A node.js library to get paths to directories to store configs, caches and data according to OS standarts.

Notifications You must be signed in to change notification settings

codingjerk/appdirsjs

Repository files navigation

appdirsjs

GitHub Workflow Status Codecov npm npm bundle size GitHub

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.

Installation

Using npm:

npm install appdirsjs

Or if you use Yarn:

yarn install 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

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

TODO

  • Android support
  • XDG on BSD support

About

A node.js library to get paths to directories to store configs, caches and data according to OS standarts.

Resources

Code of conduct

Stars

Watchers

Forks

Sponsor this project

Contributors 4

  •  
  •  
  •  
  •