express-transform

1.0.1 • Public • Published

WIP

express-transform

Build Status

Install

npm install --save express-transform

Usage

Adds a req.transform method that can be used to pipe the response to transform streams before it is passed to the underlying socket.

See ./test/index.js.

Example for compressing response:

import express from 'express';
import onHeaders from 'on-headers';
import transform from 'express-transform';

const app = express();
app.use(transform());
app.use((req, res, next) => {
  const gzip = zlib.createGzip();
  res.transform(gzip);

  // Some express methods automatically
  // add Content-Length header which will
  // be incorrect since we are compressing.
  onHeaders(res, function gzipOnHeaders() {
    this.setHeader('Content-Encoding', 'gzip');
    this.removeHeader('Content-Length');
  });

  next();
});

app.use((req, res) => {
  res.send('Hello World!');
});

Readme

Keywords

none

Package Sidebar

Install

npm i express-transform

Weekly Downloads

7

Version

1.0.1

License

MIT

Last publish

Collaborators

  • olalonde