
Research
Security News
The Landscape of Malicious Open Source Packages: 2025 Mid‑Year Threat Report
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
xdg-basedir
Advanced tools
The xdg-basedir package is a Node.js module that provides access to the XDG Base Directory Specification paths. It allows developers to easily find standard directories like configuration, data, and cache directories according to the XDG standards, which are commonly used in various Linux distributions.
Access to XDG Config Directory
This feature allows developers to retrieve the path to the user's XDG config directory, which is used to store configuration files.
const xdgBasedir = require('xdg-basedir');
console.log(xdgBasedir.config);
Access to XDG Data Directory
This feature provides the path to the XDG data directory, where applications can store data files.
const xdgBasedir = require('xdg-basedir');
console.log(xdgBasedir.data);
Access to XDG Cache Directory
This feature retrieves the path to the XDG cache directory, which is intended for non-essential data files.
const xdgBasedir = require('xdg-basedir');
console.log(xdgBasedir.cache);
Similar to xdg-basedir, env-paths computes paths for storing things like data, config, cache, etc. It works across different platforms (Windows, macOS, Linux), providing a broader scope compared to xdg-basedir which primarily targets XDG standards on Unix-like systems.
appdirs is another package that provides similar functionality to xdg-basedir, offering a simple interface to find appropriate platform-specific dirs (like those for data or config). It is also cross-platform and provides more comprehensive support for different operating systems compared to xdg-basedir.
Get XDG Base Directory paths
This package is meant for Linux. You should not use XDG on macOS or Windows. Instead, you should follow their platform conventions. You can use env-paths
for that.
$ npm install xdg-basedir
import {xdgData, xdgConfig, xdgDataDirectories} from 'xdg-basedir';
console.log(xdgData);
//=> '/home/sindresorhus/.local/share'
console.log(xdgConfig);
//=> '/home/sindresorhus/.config'
console.log(xdgDataDirectories);
//=> ['/home/sindresorhus/.local/share', '/usr/local/share/', '/usr/share/']
The exports xdgData
, xdgConfig
, xdgCache
, xdgRuntime
will return undefined
in the uncommon case that both the XDG environment variable is not set and the users home directory can't be found. You need to handle this case. A common solution is to fall back to a temporary directory.
Directory for user-specific data files.
Directory for user-specific configuration files.
Directory for user-specific state files.
Directory for user-specific non-essential data files.
Directory for user-specific non-essential runtime files and other file objects (such as sockets, named pipes, etc).
Preference-ordered array of base directories to search for data files in addition to xdgData
.
Preference-ordered array of base directories to search for configuration files in addition to xdgConfig
.
FAQs
Get XDG Base Directory paths
The npm package xdg-basedir receives a total of 6,767,974 weekly downloads. As such, xdg-basedir popularity was classified as popular.
We found that xdg-basedir demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.