Registry / storage / appdirsjs

appdirsjs

JSON →
library1.2.7jsnpmunverified

A lightweight zero-dependency JavaScript library (v1.2.7) for resolving OS-standard application directories for cache, config, and data files. Works on Linux (XDG), macOS (Apple conventions), and Windows (FOLDERID). Ships TypeScript types and supports legacy fallback via `legacyPath`. Unlike similar Python-inspired libraries, it is minimal, synchronous, and specifically designed for cross-platform Node.js apps. Released under MIT license with no notable release cadence (last stable version).

npm install appdirsjs
INSTALL
IMPORT
SIG · APPDIRSJS
A
appdirsjs
storagejavascriptv1.2.7
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.

default
import appDirs from 'appdirsjs'
const appDirs = require('appdirsjs')
ESM-only module; do not use CommonJS require
appDirs
import * as appdirs from 'appdirsjs'
import { appDirs } from 'appdirsjs'
The library exports a single function as default; no named export

Shows how to get OS-standard cache, config, and data directories for an application named 'myapp'.

import appDirs from 'appdirsjs'; const dirs = appDirs({ appName: 'myapp' }); console.log('Cache:', dirs.cache); console.log('Config:', dirs.config); console.log('Data:', dirs.data);
Debug
Known issues
gotchaCommonJS `require('appdirsjs')` fails because the library is ESM-only.
fix
Use dynamic import: `const appDirs = await import('appdirsjs')` or configure your project for ESM.
affects: >=1.0.0
gotchaThe `appName` option is required; omitting it throws an error.
fix
Always provide an `appName` string.
affects: >=1.0.0
gotcha`legacyPath` must be an absolute path; relative paths may produce unexpected results.
fix
Use `path.join(os.homedir(), '.myapp')` to construct an absolute path.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'appdirsjs'
Package not installed or incorrect import path.
fix
Run `npm install appdirsjs` and ensure `import` is from 'appdirsjs' (not a subpath).
appDirs is not a function
Using CommonJS `require()` instead of ESM `import`.
fix
Switch to `import appDirs from 'appdirsjs'` or use dynamic import.
TypeError: appDirs is not iterable
Destructuring the default import as if it's an object.
fix
Use `const dirs = appDirs(...)` not `const { cache } = appDirs(...)`.
Upgrade
Version history
1.2.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
45 hits · last 30 days
node
38
Resources
appdirsjs — npm install appdirsjs · libregistry