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.

Try it yourself

Paste your long prompt into the playground, ask a question, and see what SuperCompress keeps and removes. Free, no signup needed.

Open the Playground Embed the badge