Registry / testing / dir
library1.0.0jsnpmunverified

The `dir` package, version 0.1.2, provides a utility for Node.js to inspect objects in a 'Firebug-like' manner. Published over a decade ago, its primary goal was to offer more comprehensive object inspection, including prototype chain traversal, than Node.js's built-in `util.inspect` at the time. Unlike `util.inspect`, it aimed to return a real object for shell integration and better-colored output, even monkey-patching `console.dir`. The package has seen no updates since its initial release and is considered abandoned, with modern Node.js `console.dir` and `util.inspect` offering robust and actively maintained alternatives that supersede its original functionality. It is not compatible with modern ESM environments without additional tooling.

npm install dir
INSTALL
IMPORT
SIG · DIR
D
dir
testingjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dir
const dir = require('dir');
import dir from 'dir'; import { dir } from 'dir';
This package is a CommonJS module and must be imported using `require()` in Node.js environments. Direct ESM `import` statements will fail.
console.dir (monkey-patch)
require('dir'); console.dir(myObject);
import 'dir'; // Does not monkey-patch console.dir in ESM
The package monkey-patches the global `console.dir` when `require('dir')` is executed. This behavior is specific to CommonJS and will not occur with ESM `import` statements.

Demonstrates importing the `dir` utility and using it for inspecting various JavaScript objects, including a custom class instance, a function, and a native Date object. It also shows the effect of its `console.dir` monkey-patch.

const dir = require('dir'); class MyClass { constructor(name) { this.name = name; this.version = '1.0'; } greet() { return `Hello, ${this.name}!`; } } const instance = new MyClass('World'); // Basic object inspection console.log('--- Inspecting a simple object ---'); dir(instance); // Inspecting a function console.log('\n--- Inspecting a function ---'); dir(instance.greet); // Inspecting a native object console.log('\n--- Inspecting a native object (Date) ---'); dir(new Date()); // The package also monkey-patches console.dir console.log('\n--- Using the monkey-patched console.dir ---'); console.dir({ a: 1, b: { c: 2, d: [3, 4] } });
Debug
Known issues
breakingThis package is a legacy CommonJS module and is not compatible with Node.js ES Modules (ESM) without a CommonJS wrapper or specific build configurations (e.g., using `createRequire` or a bundler). Direct `import` statements will result in errors.
fix
Use `const dir = require('dir');` in a CommonJS context. For ESM, consider `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const dir = require('dir');` or use modern alternatives.
affects: 0.1.2
deprecatedThe `dir` package (v0.1.2) has been abandoned for over a decade. It lacks maintenance, security updates, and compatibility with modern JavaScript features or Node.js versions beyond its original release era. Its functionality is largely superseded by Node.js's built-in `console.dir()` and `util.inspect()` methods, which are actively maintained and more robust.
fix
Avoid using this package in new projects. For object inspection, prefer Node.js's native `console.dir()` or `require('util').inspect()` for better performance, compatibility, and security. For browser-like debugging, use browser developer tools.
affects: 0.1.2
gotchaThe package monkey-patches the global `console.dir` function upon `require('dir')`. This global modification can lead to unexpected behavior or conflicts with other libraries that might also modify `console` methods, making debugging difficult or changing the behavior of other parts of your application.
fix
Be aware of the global side effect. If using this package, ensure it does not conflict with other parts of your codebase or third-party libraries. In most cases, relying on `console.dir` or `util.inspect` directly without a monkey-patch is safer and more predictable.
affects: 0.1.2
Errors
Common errors & fixes
ReferenceError: require is not defined in ES module scope
Attempting to use `require()` in a Node.js ES Module (ESM) file (e.g., a file with `.mjs` extension or `type: "module"` in `package.json`).
fix
If you must use this package in ESM, create a CommonJS wrapper or use `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const dir = require('dir');`. Otherwise, convert your file to CommonJS or use `console.dir` / `util.inspect`.
TypeError: dir is not a function
The `dir` function was not correctly imported or the module did not export a function as expected, likely due to a CommonJS/ESM mismatch or a typo.
fix
Ensure you are using `const dir = require('dir');` in a CommonJS environment. Double-check for typos in the variable name or import path.
Error: Cannot find module 'dir'
The `dir` package was not installed or is not resolvable from the current execution context.
fix
Run `npm install dir` to add the package to your `node_modules`. Ensure the `require('dir')` call is within a directory where `node_modules/dir` is accessible.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
dir — npm install dir · libregistry