Registry / storage / env-paths

env-paths

JSON →
library4.0.0jsnpmunverified

Small library to retrieve OS-specific paths for storing data, config, cache, logs, and temp files. Version 4.0.0 requires Node >=20, ships TypeScript definitions, and is ESM-only. Correctly implements XDG Base Directory (Linux), macOS conventions, and Windows %APPDATA%/%LOCALAPPDATA%. Unlike ad-hoc path joining, env-paths avoids common portability mistakes. Published by Sindre Sorhus; stable API with infrequent updates.

npm install env-paths
INSTALL
IMPORT
SIG · ENV-PATHS
E
env-paths
storagejavascriptv4.0.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.

default
import envPaths from 'env-paths'
const envPaths = require('env-paths')
ESM-only package since v4; CommonJS require will fail.
envPaths
import envPaths from 'env-paths'
import { envPaths } from 'env-paths'
This package has a default export, not a named export.
Paths type
import type { Paths } from 'env-paths'
TypeScript users can import the type for return value annotations.

Shows how to import envPaths, generate paths for 'MyApp', and create those directories (the library does not create them).

import envPaths from 'env-paths'; import { mkdirSync } from 'node:fs'; const paths = envPaths('MyApp', { suffix: 'nodejs' }); // You must create directories yourself for (const dir of Object.values(paths)) { mkdirSync(dir, { recursive: true }); } console.log('Data directory:', paths.data); console.log('Config directory:', paths.config); console.log('Cache directory:', paths.cache);
Debug
Known issues
breakingVersion 4.0.0 drops CommonJS support. Package is ESM-only.
fix
Use dynamic import() or migrate to ESM. If using TypeScript, set module to 'ESNext' or 'NodeNext'.
affects: >=4.0.0
breakingMinimum Node.js version raised to 20 in v4.0.0.
fix
Upgrade Node.js to v20 or later.
affects: >=4.0.0
gotchaThe library does not create directories; you must call mkdir() yourself.
fix
After obtaining paths, use fs.mkdirSync(path, { recursive: true }) or the promise-based equivalent.
affects: *
gotchaDefault suffix is 'nodejs' to avoid collisions with native apps. Override with empty string to remove suffix.
fix
Call envPaths('AppName', { suffix: '' }) for paths without suffix.
affects: *
deprecatedNo deprecated features known, but v3 users must update to ESM for v4.
fix
Switch to ESM imports and update Node to >=20.
affects: <4.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module
Using CommonJS require() on an ESM-only package (v4).
fix
Replace require('env-paths') with import envPaths from 'env-paths'.
ENOENT: no such file or directory, open '...'
Trying to write to a path that does not exist because env-paths only generates the path string.
fix
Call mkdirSync(paths.data, { recursive: true }) before writing files.
TypeError: envPaths is not a function
Using a named import { envPaths } when the module exports a default function.
fix
Use import envPaths from 'env-paths'.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
33 hits · last 30 days
node
30
Amazon
1
OpenAI (training)
1
Resources
env-paths — npm install env-paths · libregistry