{"id":13071,"library":"dir","title":"Node.js `dir()` Object Inspector","description":"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.","status":"abandoned","version":"0.1.2","language":"javascript","source_language":"en","source_url":"git://github.com/aseemk/node-dir","tags":["javascript","dir","shell","firebug","util","inspect"],"install":[{"cmd":"npm install dir","lang":"bash","label":"npm"},{"cmd":"yarn add dir","lang":"bash","label":"yarn"},{"cmd":"pnpm add dir","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is a CommonJS module and must be imported using `require()` in Node.js environments. Direct ESM `import` statements will fail.","wrong":"import dir from 'dir';\nimport { dir } from 'dir';","symbol":"dir","correct":"const dir = require('dir');"},{"note":"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.","wrong":"import 'dir'; // Does not monkey-patch console.dir in ESM","symbol":"console.dir (monkey-patch)","correct":"require('dir');\nconsole.dir(myObject);"}],"quickstart":{"code":"const dir = require('dir');\n\nclass MyClass {\n  constructor(name) {\n    this.name = name;\n    this.version = '1.0';\n  }\n  greet() {\n    return `Hello, ${this.name}!`;\n  }\n}\n\nconst instance = new MyClass('World');\n\n// Basic object inspection\nconsole.log('--- Inspecting a simple object ---');\ndir(instance);\n\n// Inspecting a function\nconsole.log('\\n--- Inspecting a function ---');\ndir(instance.greet);\n\n// Inspecting a native object\nconsole.log('\\n--- Inspecting a native object (Date) ---');\ndir(new Date());\n\n// The package also monkey-patches console.dir\nconsole.log('\\n--- Using the monkey-patched console.dir ---');\nconsole.dir({ a: 1, b: { c: 2, d: [3, 4] } });","lang":"javascript","description":"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."},"warnings":[{"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.","message":"This 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.","severity":"breaking","affected_versions":"0.1.2"},{"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.","message":"The `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.","severity":"deprecated","affected_versions":"0.1.2"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"0.1.2"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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`.","cause":"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`).","error":"ReferenceError: require is not defined in ES module scope"},{"fix":"Ensure you are using `const dir = require('dir');` in a CommonJS environment. Double-check for typos in the variable name or import path.","cause":"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.","error":"TypeError: dir is not a function"},{"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.","cause":"The `dir` package was not installed or is not resolvable from the current execution context.","error":"Error: Cannot find module 'dir'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}