Integration guide

Express.js compression integration

Express.js is the standard Node.js web framework. Add SuperCompress as middleware to automatically compress LLM requests.

By Arjun Shah - Creator of SuperCompress - Updated 2026-07-03

Express middleware

const fetch = require("node-fetch");
const SUPERCOMPRESS_KEY = process.env.SUPERCOMPRESS_API_KEY;

async function compressMiddleware(req, res, next) {
    if (req.path === "/api/chat" && req.method === "POST") {
        const { context, query } = req.body;
        if (context && query) {
            const resp = await fetch(
                "https://supercompress.dev/api/v1/compress",
                {
                    method: "POST",
                    headers: {
                        "Content-Type": "application/json",
                        "X-API-Key": SUPERCOMPRESS_KEY,
                    },
                    body: JSON.stringify({ context, query }),
                }
            );
            const data = await resp.json();
            req.body.context = data.compressed_text;
        }
    }
    next();
}

app.use(compressMiddleware);

Frequently asked questions

Does this work with Express async routes?

Yes. The middleware is async-compatible.

Can I use it with NestJS?

Yes. Create a NestJS interceptor that calls the compression API.

Build with less context

Put compression in front of your next LLM call.

Use the hosted API or run SuperCompress locally. Keep the evidence, drop the token waste, and measure the savings before it reaches your model.

Get an API keyRead the guide