npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

express-file-compressor

v1.0.2

Published

Flexible and configurable Multer wrapper for file uploads supporting auto-conversion and compression of images, videos, audio, documents (to PDF), and generic archiving.

Readme

Express File Compressor

GitHub repository

A flexible, drop-in wrapper over Multer memory storage designed for easy media processing, conversion, and compression on local environments. Handles Images (using sharp), Videos & Audios (using fluent-ffmpeg), Document to PDF conversion (using LibreOffice), PDF optimization, and ZIP generation out of the box.


Features

  • 🚀 Drop-in Middleware: Integrates directly into your existing Express/Multer endpoints.
  • 🖼️ Image Compression: Auto-converts to WebP/AVIF, resizes, and optimizes images using sharp.
  • 📽️ Video & Audio: Compress and transcode videos or audio tracks using fluent-ffmpeg.
  • 📄 Doc → PDF Converter: Convert DOCX, PPTX, and XLSX files to PDF on-the-fly via headless LibreOffice.
  • 🗜️ PDF Optimizer & Zip Generator: Compress PDFs and pack files into ZIP archives programmatically.

Installation

npm install express-file-compressor

System Requirements (Optional, based on features used)

  • Video/Audio processing: Install ffmpeg on your host system and include fluent-ffmpeg in your project.
  • Document conversion: Install libreoffice and ensure the soffice command is available in your PATH.

Quick Start (Express Middleware)

const express = require('express');
const flexiMedia = require('express-file-compressor');

const app = express();

// Initialize the media handler middleware
const media = flexiMedia({
  uploadDir: './uploads', // where processed files are stored
  debug: true
});

// Upload single file (automatic conversion to WebP for images)
app.post('/upload', media.single('file'), (req, res) => {
  res.json({
    message: "Upload and processing complete!",
    file: req.file // file.path points to the compressed file
  });
});

// Upload multiple files
app.post('/upload-multiple', media.array('photos', 5), (req, res) => {
  res.json({
    files: req.files
  });
});

Advanced Configuration: Custom Rules

You can fully customize matching criteria, formats, and compression parameters by passing custom rules.

const media = flexiMedia({
  uploadDir: './uploads',
  rules: [
    // 1. Process PNGs to high-quality AVIF
    {
      name: "Convert PNG to AVIF",
      match: (file) => file.mimetype === 'image/png',
      convert: 'image',
      options: { format: 'avif', quality: 80 }
    },
    // 2. Transcode heavy videos to lightweight MP4s
    {
      name: "Compress mp4 video",
      match: (file) => file.mimetype.startsWith('video/'),
      convert: 'video',
      options: { format: 'mp4', videoBitrate: '800k', resolution: '640x?' }
    },
    // 3. Keep original TXT files untouched
    {
      name: "Pass-through text files",
      match: (file) => file.extension === 'txt',
      convert: null // No conversion/compression applied
    }
  ]
});

Direct Programmatic Usage (Without Middleware)

You can also import and use the underlying converters directly inside your application logic.

const { converters } = require('express-file-compressor')();

// 1. Compress Image
const webpBuffer = await converters.compressImage(rawImageBuffer, {
  format: 'webp',
  quality: 80,
  width: 800
});

// 2. Convert Word Document to PDF
const pdfBuffer = await converters.convertDocToPdf(docxBuffer, 'docx');

// 3. Compress files into a ZIP
const zipBuffer = await converters.compressToZip([
  { name: 'document.pdf', buffer: pdfBuffer },
  { name: 'image.webp', buffer: webpBuffer }
]);

License

MIT