Registry / storage / xdg-app-paths

xdg-app-paths

JSON →
library8.3.0jsnpmunverified

Determine XDG-compatible paths for storing application files (cache, config, data, etc) on Linux, macOS, and Windows. Version 8.3.0 supports CJS, ESM, TypeScript, and Deno. Actively maintained with regular releases. Unlike similar libraries, it automatically derives application name from the calling module's filename and provides a separate CJS entry point.

npm install xdg-app-paths
INSTALL
IMPORT
SIG · XDG-APP-PATHS
X
xdg-app-paths
storagejavascriptv8.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

xdgAppPaths
import xdgAppPaths from 'xdg-app-paths'
import { xdgAppPaths } from 'xdg-app-paths'
Default import. Named import does not exist.
xdgAppPaths
const xdgAppPaths = require('xdg-app-paths/cjs')
const xdgAppPaths = require('xdg-app-paths')
CommonJS users must require from 'xdg-app-paths/cjs', not the main entry.
xdgAppPaths
import xdgAppPaths from 'https://deno.land/x/xdg_app_paths@v8.3.0/src/mod.deno.ts'
import xdgAppPaths from 'xdg-app-paths'
Deno requires the full URL to the Deno-specific module.

Demonstrates all major XDG path retrieval methods with cross-platform examples.

import xdgAppPaths from 'xdg-app-paths'; // Get XDG directories for the application named 'myapp' const cacheDir = xdgAppPaths.cache(); console.log('Cache directory:', cacheDir); // Linux: /home/user/.cache/myapp // macOS: /Users/user/Library/Caches/myapp // Windows: C:\Users\user\AppData\Local\myapp\Cache const configDir = xdgAppPaths.config(); console.log('Config directory:', configDir); // Linux: /home/user/.config/myapp // macOS: /Users/user/Library/Application Support/myapp // Windows: C:\Users\user\AppData\Roaming\myapp\Config const dataDir = xdgAppPaths.data(); console.log('Data directory:', dataDir); // Linux: /home/user/.local/share/myapp // macOS: /Users/user/Library/Application Support/myapp // Windows: C:\Users\user\AppData\Roaming\myapp\Data const configDirs = xdgAppPaths.configDirs(); console.log('Config directories (priority order):', configDirs); // Linux: ['/home/user/.config/myapp', '/etc/xdg/myapp'] // macOS: ['/Users/user/Library/Application Support/myapp', '/Library/Application Support/myapp'] // Windows: ['C:\Users\user\AppData\Roaming\myapp\Config'] const runtimeDir = xdgAppPaths.runtime(); console.log('Runtime directory:', runtimeDir); // Linux: /run/user/1000/myapp // macOS: null (not supported) // Windows: null (not supported) const stateDir = xdgAppPaths.state(); console.log('State directory:', stateDir); // Linux: /home/user/.local/state/myapp // macOS: /Users/user/Library/State/myapp // Windows: C:\Users\user\AppData\Local\myapp\State
Debug
Known issues
breakingVersion 8.x changed the required import for CommonJS from 'xdg-app-paths' to 'xdg-app-paths/cjs'. Old CJS code using require('xdg-app-paths') will fail.
fix
Change require('xdg-app-paths') to require('xdg-app-paths/cjs').
affects: >=8.0.0
breakingVersion 8.x removed the default export of a class; it now exports a function directly. const xdg = new xdgAppPaths() no longer works.
fix
Use xdgAppPaths.cache() etc. directly; the function is called without instantiation.
affects: >=8.0.0
gotchaThe library automatically determines the application name from the calling module's filename (e.g., myapp.js results in 'myapp'). This may not be intended for applications with multiple entry points or different naming conventions.
fix
Use a wrapper or pass the app name explicitly? (No built-in override; consider using environment variable XDG_APP_PATHS_NAME or similar workaround.)
affects: >=8.0.0
gotchaOn Windows, the method 'runtime()' returns null because runtime directories are not part of the XDG spec on Windows. Similarly, 'state()' and 'data()' may return different paths than expected.
fix
Always check for null return values on methods not supported on Windows (e.g., runtime).
affects: >=8.0.0
deprecatedThe method 'configDirs()' returns an array of directories in priority order. In future versions this may be renamed to 'configPaths()' to align with other path methods.
fix
Use 'configDirs()' as-is for now, but be prepared for renaming in future major releases.
affects: >=8.0.0
Errors
Common errors & fixes
Cannot find module 'xdg-app-paths'
CommonJS code using require('xdg-app-paths') instead of require('xdg-app-paths/cjs')
fix
Change to const xdgAppPaths = require('xdg-app-paths/cjs');
TypeError: xdgAppPaths is not a constructor
Attempting to instantiate the default export with 'new xdgAppPaths()'
fix
Use 'xdgAppPaths.cache()' etc. directly, no instantiation needed.
SyntaxError: The requested module 'xdg-app-paths' does not provide an export named 'xdgAppPaths'
Using named import { xdgAppPaths } from 'xdg-app-paths' instead of default import
fix
Use 'import xdgAppPaths from 'xdg-app-paths'' (default import).
Upgrade
Version history
8.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
34 hits · last 30 days
node
30
OpenAI (training)
1
Resources