push-stream-std

@push-stream-std/push-http-server (0.0.10)

Published 2026-07-21 03:59:00 +00:00 by Dvorak

Installation

@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/
npm install @push-stream-std/push-http-server@0.0.10
"@push-stream-std/push-http-server": "0.0.10"

About this package

@push-stream-std/push-http-server

HTTP server as a push-stream source.

Published as @push-stream-std/push-http-server.

Synopsis

import { httpServer, createHandler } from '@push-stream-std/push-http-server';

// Low-level: get raw req/res pairs
httpServer({ host: '127.0.0.1', port: 8080 }).pipe({
  write({ req, res, source, sink }) {
    console.log(req.method, req.url);
    sink.end();
    res.end('Hello\n');
  },
  end(err) { if (err) console.error(err); },
  abort(err) { console.error('aborted:', err); },
  paused: false
});

// High-level: get parsed request info
const handler = createHandler((req, res) => {
  console.log(req.method, req.url, req.headers);
  res.writeHead(200);
  res.end(JSON.stringify({ body: req.body?.toString() }));
});

handler.listen(8080, () => console.log('listening'));

Install

npm config set @push-stream-std:registry https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/
npm config set -- //hub.kl1.tenere.ai/api/packages/push-stream-std/npm/:_authToken "$PACKAGE_TOKEN"
npm install @push-stream-std/push-http-server

Why

Wraps Node.js http.createServer as a push-stream source. Two APIs are provided: httpServer emits { req, res, source, sink } objects for each connection, with source/sink being push-stream interfaces wrapping the request body and response. createHandler provides a higher-level API that emits { method, url, headers, body, res } objects after buffering the full request body.

API

httpServer(options)

  • options.host - string (default: '127.0.0.1') - Host to bind to.
  • options.port - number (default: 0) - Port to listen on. 0 picks a random available port.

Returns a push-stream source. Pipe it to a sink to receive connection objects:

  • connection.req - Node.js IncomingMessage
  • connection.res - Node.js ServerResponse
  • connection.source - Push-stream source emitting request body chunks
  • connection.sink - Push-stream sink for writing responses

Call source.abort(err) to close the server.

createHandler(handlerFn)

  • handlerFn - function(req, res) - Called for each incoming request.

Returns a source-like object with additional methods:

  • source.pipe(sink) - Pipe to a sink that receives { method, url, headers, body, res } objects.
  • source.listen(port, [host], [callback]) - Start listening on the given port.
  • source.close([callback]) - Close the server.
  • source.abort(err) - Close the server with an error.

Tests

npm test

Tests cover source creation, emitting parsed requests with method/url/headers/body.

Requirements

Node.js 22 or later. ESM only.

Dependencies

Dependencies

ID Version
@push-stream-std/push-stream-base *

Keywords

push-stream stream http server
Details
npm
2026-07-21 03:59:00 +00:00
0
SEE LICENSE IN LICENSE
latest
4.2 KiB
Assets (1)
Versions (6) View all
0.0.10 2026-07-21
0.0.9 2026-07-20
0.0.8 2026-07-20
0.0.6 2026-07-19
0.0.5 2026-07-19