Registry / http-networking / union
library0.1.203jsnpmunverified

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 union
INSTALL
IMPORT
SIG · UNION
U
union
http-networkingjavascriptv0.1.203
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.

createServer
const union = require('union'); const server = union.createServer({});
import { createServer } from 'union';
Union is a CommonJS module. ESM import syntax is not supported. `createServer` is the primary entry point for creating a Union HTTP server.
union
const union = require('union');
import union from 'union';
The package exports an object containing its utilities, not a default export. It is a CommonJS module.
ResponseStream
const ResponseStream = union.ResponseStream;
const { ResponseStream } = require('union');
`ResponseStream` is exposed as a property of the `union` module, used for defining custom stream filters.

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.

const fs = require('fs'); const union = require('union'); const director = require('director'); const router = new director.http.Router(); const server = union.createServer({ before: [ function (req, res) { const found = router.dispatch(req, res); if (!found) { res.emit('next'); // For Flatiron-compatible middlewares } } ] }); router.get(/foo/, function () { this.res.writeHead(200, { 'Content-Type': 'text/plain' }); this.res.end('hello world\n'); }); router.post(/foo/, { stream: true }, function () { const req = this.req; const res = this.res; const writeStream = fs.createWriteStream(Date.now() + '-foo.txt'); req.pipe(writeStream); writeStream.on('close', function () { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Wrote request body to a stream!'); }); }); server.listen(9090, () => { console.log('Union server with director running on port 9090'); }); // To run this example, ensure 'director' is installed: npm install director
Debug
Known issues
breakingThe `union` package is effectively abandoned and unmaintained. Its `package.json` specifies `node >= 0.8.0`, indicating compatibility with extremely old Node.js versions, and it has not been updated in over two years.
fix
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.
affects: >=0.6.0
gotchaCompatibility with `connect` middlewares is explicitly stated for `union 0.3.x` with `connect >= 2.1.0`. Later versions of `connect` (e.g., `3.x` or `2.x` versions not strictly `>= 2.1.0`) may not work as expected due to API changes.
fix
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.
affects: <=0.6.0
gotchaUnion's response object (`res`) in middlewares uses `res.emit('next')` for control flow, a pattern specific to the Flatiron ecosystem. This is not reverse-compatible with standard `connect` middlewares that expect a `next()` callback as the third argument.
fix
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.
affects: <=0.6.0
Errors
Common errors & fixes
Error: listen EADDRINUSE :::9090
Another process is already using the port that the `union` server is attempting to listen on.
fix
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`.
TypeError: connect is not a function
You are attempting to use the `connect` module in an incompatible way with a CommonJS context, or an incorrect version of `connect` is installed.
fix
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.
Error: Cannot find module 'director'
The `director` package, used in many `union` examples for routing, is not installed in your project.
fix
Install the `director` package: `npm install director`.
Upgrade
Version history
0.1.203latest on npm
Audit
Dependencies
connectoptionalOften used for middleware compatibility; explicitly mentioned for integration. `union` version 0.3.x is compatible with `connect >= 2.1.0`.
directoroptionalFrequently demonstrated in examples for routing, part of the Flatiron ecosystem.
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
union — npm install union · libregistry