x-path - Node.js Path Module Extension
raw JSON →The `x-path` package extends Node.js's native `path` module, providing additional utilities for path manipulation and basic file system checks. It offers methods such as `isAbsolutePath`, `isRelativePath`, `isRootDirectory`, `unifyPathSeparate`, `normalizePathSeparate`, and functions to check if a path refers to a directory or file (`isDirectory`, `isFile`, `isDirectorySync`, `isFileSync`). It also includes functions for retrieving common system directories like `tempdir`, `homedir`, and `datadir`, which are sourced from the `path-extra` package. The current and only release is version 0.0.2, published in 2015. Given its age and complete lack of updates, the package is considered abandoned, with no active development or release cadence. Its initial purpose was to fill gaps in Node.js's built-in `path` module, many of which have since been addressed by the core Node.js `path`, `os`, and `fs` modules, or by widely adopted and maintained third-party alternatives.
Common errors
error ReferenceError: require is not defined ↓
import { isAbsolute } from 'node:path';) or modern alternatives. If in a browser, use client-side path utilities or a bundler to transpile. error TypeError: path.isAbsolutePath is not a function ↓
const path = require('x-path'); and then access methods as path.isAbsolutePath(somePath);. Ensure require('x-path') successfully returns the module object. error MODULE_NOT_FOUND: Cannot find package 'x-path' imported from ... ↓
npm install x-path has been run. If in an ESM project, this package is not designed for direct import. Consider migrating to native Node.js path, os, and fs modules, which are ESM-compatible. Otherwise, if interoperability is configured, ensure correct path resolution. Warnings
breaking The package is effectively abandoned, with its last update in 2015 (version 0.0.2). It is not compatible with modern Node.js module systems (ESM) and its internal dependencies may contain unpatched vulnerabilities or rely on outdated APIs. ↓
gotcha This package is CommonJS-only. Attempting to use `import` statements directly in an ESM project will result in module resolution errors. It was published long before widespread ESM adoption in Node.js. ↓
deprecated Many of the utilities provided by `x-path`, such as `isAbsolutePath`, `homedir`, and `tempdir`, now have direct equivalents in Node.js's built-in `path` and `os` modules. The `fs.stat` methods provide robust, asynchronous file system checks. ↓
gotcha The `isDirectorySync` and `isFileSync` methods perform synchronous file system operations. These block the Node.js event loop, leading to performance issues and unresponsiveness, especially in server applications or for large file operations. ↓
Install
npm install x-path yarn add x-path pnpm add x-path Imports
- path wrong
import path from 'x-path';correctconst path = require('x-path'); - isAbsolutePath wrong
import { isAbsolutePath } from 'x-path';correctconst path = require('x-path'); path.isAbsolutePath('/foo/bar'); - isDirectorySync wrong
const { isDirectorySync } = require('x-path');correctconst path = require('x-path'); path.isDirectorySync('./my-dir');
Quickstart
const path = require('x-path');
const fs = require('fs');
const os = require('os');
// Create a dummy file and directory for testing file system checks
const testDirPath = './temp-test-dir';
const testFilePath = './temp-test-dir/test-file.txt';
if (!fs.existsSync(testDirPath)) {
fs.mkdirSync(testDirPath);
}
fs.writeFileSync(testFilePath, 'Hello, x-path!');
console.log('--- x-path Usage Examples ---');
// Path checks
console.log(`Is '/usr/local/bin' an absolute path? ${path.isAbsolutePath('/usr/local/bin')}`);
console.log(`Is 'relative/path' a relative path? ${path.isRelativePath('relative/path')}`);
// File system checks (synchronous, generally discouraged)
console.log(`Is '${testDirPath}' a directory? ${path.isDirectorySync(testDirPath)}`);
console.log(`Is '${testFilePath}' a file? ${path.isFileSync(testFilePath)}`);
console.log(`Is './nonexistent' a directory? ${path.isDirectorySync('./nonexistent')}`);
// System directories
console.log(`Temporary directory: ${path.tempdir()}`);
console.log(`Home directory: ${path.homedir()}`);
// Clean up dummy files/directories
fs.unlinkSync(testFilePath);
fs.rmdirSync(testDirPath);
console.log('\nCleaned up temporary test files.');