Union is a Node.js middleware kernel designed to provide a hybrid buffered and streaming approach to handling HTTP requests and responses. It aims for backward compatibility with `connect` middlewares, allowing existing `connect` applications to leverage its features. The current stable version is 0.6.0, last published over two years ago as of early 2024. The package's `engines` configuration (`node >= 0.8.0`) further indicates its age and lack of recent maintenance. Key differentiators include its streaming middleware architecture, which avoids buffering entire request streams, and its integration with the Flatiron ecosystem, notably with `director` for routing. Unlike standard `connect` middlewares, `union`'s response object emits a 'next' event for control flow, a pattern used by Flatiron-specific middlewares but not directly compatible in reverse with `connect`'s `next()` callback style.
npm install unionVerified import paths — ran on the pinned version, not inferred.
This example sets up a basic Union server with `director` for routing. It demonstrates defining `before` middlewares, handling GET requests, and streaming POST request bodies to a file, showcasing Union's core streaming capabilities.
Consider migrating to actively maintained web frameworks like Express, Koa, or Fastify, which offer similar middleware patterns and modern Node.js support. This package is not suitable for new projects or production use.
If using `union` with `connect`, ensure you use `connect` version `2.x.x` (specifically `>= 2.1.0`) to maintain compatibility. Do not use `connect 3.x` or later.
When writing middlewares for `union` that need to pass control, use `res.emit('next')` if following the Flatiron style. If integrating with existing `connect` middlewares, be aware of this difference and adapt accordingly, potentially by wrapping `connect` middlewares.Ensure no other application is running on the specified port, or choose a different port for your `union` server. On Linux/macOS, you can find processes using a port with `lsof -i :9090`.
Ensure `connect` is installed (`npm install connect@2`). If using `connect` v3+, it changed its API and might not be directly compatible without adapters. Also, `union` is CJS-only, so modern ESM `connect` versions will require specific interoperability layers if they even work.
Install the `director` package: `npm install director`.