`trough` is a lightweight, promise-aware middleware utility designed for building flexible processing pipelines in JavaScript and TypeScript environments. Currently at version 2.2.0, it is actively maintained with a consistent release cadence for minor improvements and bug fixes, typically addressing specific use cases or compatibility enhancements. Unlike some traditional middleware solutions, `trough` allows each stage of the pipeline to modify the input for subsequent stages and seamlessly integrates both synchronous and asynchronous functions, including those that return promises or use Node.js-style callbacks. Its core differentiator lies in its minimal API and explicit control over data flow, making it suitable for scenarios like plugin systems or data transformation pipelines. It is an ESM-only package, targeting modern Node.js (v16+) and browser environments via `esm.sh`.
npm install troughVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates creating a `trough` pipeline with both synchronous and asynchronous (callback and Promise-based) middleware functions, showing how data flows and errors are handled.
Refactor module imports from `const trough = require('trough')` to `import { trough } from 'trough'` in your codebase.Ensure you are using `trough` v2.0.1 or newer if you experienced unexpected data flow issues immediately after upgrading to v2.0.0.
For Promise-based middleware, `return someAsyncFunction()`. For callback-based middleware, ensure `next(error, result)` is called. Refer to the API documentation for specific middleware signatures.
Ensure all middleware functions intended for browser execution are browser-compatible. Use bundlers like webpack or Rollup to shim Node.js modules or exclude them from browser builds if necessary.
If experiencing `this` context issues, ensure you are on v2.1.0 or newer. Use `.bind(this)` or arrow functions to explicitly control `this` when needed.
Convert your module to ESM or update your tooling configuration to handle ESM imports. Use `import { trough } from 'trough'` instead.Ensure your import statement matches `import { trough } from 'trough'` and your TypeScript `tsconfig.json` `module` option is set to `ESNext` or `Node16` if targeting modern Node.js.Refactor the problematic middleware to use browser-compatible APIs or ensure it's only run in a Node.js context. For shared code, abstract platform-specific logic.
Review the middleware that threw the error (in this case, the one checking `ctx.stats.isFile()`) and ensure the input to the pipeline, or the logic within the middleware, handles all expected cases. Implement robust error handling and input validation.
No dependency data recorded yet.