{"id":18014,"library":"x-path","title":"x-path - Node.js Path Module Extension","description":"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.","status":"abandoned","version":"0.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/node-x-extras/x-path","tags":["javascript","x-path","path-extras","path-extra","path","extra","extend","npm-path","path-extend"],"install":[{"cmd":"npm install x-path","lang":"bash","label":"npm"},{"cmd":"yarn add x-path","lang":"bash","label":"yarn"},{"cmd":"pnpm add x-path","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides additional system directory functions like tempdir, homedir, and datadir.","package":"path-extra","optional":false}],"imports":[{"note":"This package is CommonJS-only. Direct ESM 'import' statements will not work without a CommonJS wrapper or bundler configuration.","wrong":"import path from 'x-path';","symbol":"path","correct":"const path = require('x-path');"},{"note":"Individual functions are exported as properties of the main `path` object, not as named exports. Modern Node.js provides `path.isAbsolute` natively.","wrong":"import { isAbsolutePath } from 'x-path';","symbol":"isAbsolutePath","correct":"const path = require('x-path');\npath.isAbsolutePath('/foo/bar');"},{"note":"Functions are properties of the main exported object. Synchronous file system operations are generally discouraged in Node.js for blocking the event loop; prefer `fs.stat` with promises or callbacks for async checks.","wrong":"const { isDirectorySync } = require('x-path');","symbol":"isDirectorySync","correct":"const path = require('x-path');\npath.isDirectorySync('./my-dir');"}],"quickstart":{"code":"const path = require('x-path');\nconst fs = require('fs');\nconst os = require('os');\n\n// Create a dummy file and directory for testing file system checks\nconst testDirPath = './temp-test-dir';\nconst testFilePath = './temp-test-dir/test-file.txt';\n\nif (!fs.existsSync(testDirPath)) {\n  fs.mkdirSync(testDirPath);\n}\nfs.writeFileSync(testFilePath, 'Hello, x-path!');\n\nconsole.log('--- x-path Usage Examples ---');\n\n// Path checks\nconsole.log(`Is '/usr/local/bin' an absolute path? ${path.isAbsolutePath('/usr/local/bin')}`);\nconsole.log(`Is 'relative/path' a relative path? ${path.isRelativePath('relative/path')}`);\n\n// File system checks (synchronous, generally discouraged)\nconsole.log(`Is '${testDirPath}' a directory? ${path.isDirectorySync(testDirPath)}`);\nconsole.log(`Is '${testFilePath}' a file? ${path.isFileSync(testFilePath)}`);\nconsole.log(`Is './nonexistent' a directory? ${path.isDirectorySync('./nonexistent')}`);\n\n// System directories\nconsole.log(`Temporary directory: ${path.tempdir()}`);\nconsole.log(`Home directory: ${path.homedir()}`);\n\n// Clean up dummy files/directories\nfs.unlinkSync(testFilePath);\nfs.rmdirSync(testDirPath);\nconsole.log('\\nCleaned up temporary test files.');","lang":"javascript","description":"Demonstrates basic path checks (`isAbsolutePath`, `isRelativePath`), synchronous file system queries (`isDirectorySync`, `isFileSync`), and retrieval of system directories (`tempdir`, `homedir`)."},"warnings":[{"fix":"Migrate to native Node.js `path`, `os`, and `fs` modules (e.g., `path.isAbsolute`, `os.homedir`, `os.tmpdir`, `fs.stat`) or use actively maintained alternatives like `fs-extra` for extended file system operations.","message":"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.","severity":"breaking","affected_versions":">=0.0.2"},{"fix":"For CommonJS, use `const path = require('x-path');`. For ESM projects, rewrite functionality using native Node.js modules or modern, ESM-compatible libraries. If absolutely necessary, you might configure a bundler to transpile or wrap CommonJS modules.","message":"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.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Replace `path.isAbsolutePath` with `path.isAbsolute` (from `node:path`), `path.homedir` with `os.homedir()` (from `node:os`), `path.tempdir` with `os.tmpdir()` (from `node:os`). For file/directory checks, use `fs.stat` or `fs.promises.stat` for asynchronous, non-blocking operations.","message":"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.","severity":"deprecated","affected_versions":">=0.0.1"},{"fix":"Always prefer asynchronous file system methods. Use `fs.promises.stat(path)` or `fs.stat(path, callback)` and check the `stats` object (`stats.isDirectory()`, `stats.isFile()`) to determine file or directory type without blocking.","message":"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.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"This package is CommonJS-only. If in an ESM project, rewrite the functionality using native Node.js modules (`import { isAbsolute } from 'node:path';`) or modern alternatives. If in a browser, use client-side path utilities or a bundler to transpile.","cause":"Attempting to use `require()` in an ES module context or a browser environment where CommonJS is not supported.","error":"ReferenceError: require is not defined"},{"fix":"The package exports a single object containing all functions. Use `const path = require('x-path');` and then access methods as `path.isAbsolutePath(somePath);`. Ensure `require('x-path')` successfully returns the module object.","cause":"Trying to destructure `isAbsolutePath` (e.g., `const { isAbsolutePath } = require('x-path');`) or calling it on an undefined `path` object.","error":"TypeError: path.isAbsolutePath is not a function"},{"fix":"Ensure `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.","cause":"Using `import path from 'x-path';` in an ES module environment without proper CommonJS interoperability configuration, or the package is simply not installed.","error":"MODULE_NOT_FOUND: Cannot find package 'x-path' imported from ..."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}