{"id":10740,"library":"dev-null","title":"dev-null Stream Sink","description":"The `dev-null` package for Node.js provides a straightforward implementation of a `/dev/null` stream, consuming all piped input data without emitting any output. This utility is particularly useful in testing, debugging, or scenarios where stream data needs to be discarded to prevent side effects, such as when monitoring stream events rather than their payload. Currently at version 0.1.1, the package is exceptionally stable due to its singular, well-defined purpose, and is not expected to receive frequent updates or new features. Its key differentiator is its minimal API and focused functionality, making it a drop-in solution for stream nullification without introducing unnecessary overhead or complex configurations, serving as a direct parallel to the Unix `/dev/null` device for data streams.","status":"active","version":"0.1.1","language":"javascript","source_language":"en","source_url":"git://github.com/thlorenz/dev-null","tags":["javascript","streams","test","debug","ignore","silence"],"install":[{"cmd":"npm install dev-null","lang":"bash","label":"npm"},{"cmd":"yarn add dev-null","lang":"bash","label":"yarn"},{"cmd":"pnpm add dev-null","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primary CommonJS import. The package exports a function, not a stream instance directly.","wrong":"import devnull from 'dev-null';","symbol":"devnull","correct":"const devnull = require('dev-null');"},{"note":"You must call `devnull()` to get a new writable stream instance to pipe into.","wrong":"someStream.pipe(devnull);","symbol":"devnull()","correct":"someStream.pipe(devnull());"},{"note":"While primarily CJS, modern Node.js ESM projects might use a default import with appropriate configuration (e.g., 'type: module' in package.json and import maps or bundlers).","wrong":"import { devnull } from 'dev-null';","symbol":"devnull (ESM)","correct":"import devnull from 'dev-null'; // With transpiler or 'type: module'"}],"quickstart":{"code":"const devnull = require('dev-null');\nconst { Readable } = require('stream');\n\n// A simple readable stream that emits numbers\nclass NumberReadable extends Readable {\n  constructor(options) {\n    super(options);\n    this.current = 0;\n    this.to = options.to || 5;\n  }\n\n  _read() {\n    if (this.current > this.to) {\n      this.push(null); // No more data\n      return;\n    }\n    this.push(Buffer.from(String(this.current++)));\n  }\n}\n\nconsole.log('--- Piping numbers to dev-null (no output expected) ---');\n\nnew NumberReadable({ to: 5 })\n  .pipe(devnull())\n  .on('data', (d) => {\n    // This event should ideally not fire if dev-null works correctly\n    console.log('Unexpected data received:', d.toString());\n  })\n  .on('end', () => {\n    console.log('Stream ended after piping to dev-null. This message indicates successful consumption.');\n  });\n\nconsole.log('\\n--- Example without dev-null (output expected) ---');\n\nnew NumberReadable({ to: 2 })\n  .on('data', (d) => {\n    console.log('Data without dev-null:', d.toString());\n  })\n  .on('end', () => {\n    console.log('Stream ended without dev-null. This message follows expected data output.');\n  });","lang":"javascript","description":"Demonstrates piping a readable stream into dev-null to silence its output, contrasting it with a stream that outputs data."},"warnings":[{"fix":"Ensure you intend to discard data. If you need transformation or logging, use a `through` stream or a custom `Writable` stream.","message":"The `dev-null` package acts as a data sink. It consumes all piped data without emitting any output itself. Expecting data to pass through or be transformed by `dev-null()` is a misunderstanding of its purpose.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"For CommonJS, use `const devnull = require('dev-null');`. For ESM, consider using `import devnull from 'dev-null';` with Node.js 'type: module' project setup or use `createRequire` if mixing CJS and ESM in a complex way.","message":"This package is a CommonJS module. When using it in an ECMAScript Module (ESM) project, direct `import devnull from 'dev-null';` might require specific Node.js configuration (e.g., 'type: module' in package.json) or a bundler to resolve correctly, potentially leading to 'require() of ES module' errors in some setups.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"No fix needed if current functionality meets requirements. For highly active development or specific modern stream features, consider if a more actively maintained alternative exists, though few would be simpler for this task.","message":"The package is at version 0.1.1 and appears to be in a very stable, low-maintenance state. While functional, it's unlikely to receive new features, active bug fixes, or updates to modern Node.js stream APIs. This is generally not an issue given its simple utility, but users should be aware of the lack of active development.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Call the `devnull` function to create an instance of the null stream: `someStream.pipe(devnull());`","cause":"Attempting to pipe directly to the imported `devnull` module (e.g., `someStream.pipe(devnull)`). The `dev-null` module exports a function that, when called, returns a new writable stream instance.","error":"TypeError: devnull is not a function"},{"fix":"Change the import to a CommonJS `require` statement: `const devnull = require('dev-null');` or configure your project as an ESM module by adding `\"type\": \"module\"` to your `package.json`.","cause":"Trying to use `import devnull from 'dev-null';` in a Node.js environment configured for CommonJS (e.g., no `\"type\": \"module\"` in `package.json`).","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}