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-image-server

v1.0.4

Published

A Node.js middleware for creating image servers

Readme

express-image-server

express-image-server is a node.js middleware for creating image servers. It provides middlewares for search, process and upload images in real time. For processing images the lib uses sharp, a high performance image processor for Node.js applications. And for uploading images it uses multer.

Table of contents

Installation

$ yarn add express-image-server

Basic usage

import path from 'path'
import express from 'express'
import { DiskStorage, processMiddleware, uploadMiddleware } from 'express-image-server'

const app = express()

// Create a local storage client, from where the images will be fetched and saved.
const diskStorage = new DiskStorage({
  dest: path.resolve(__dirname, '..', 'images'),
})

// Set the processing image middleware
app.get(
  '/images/:id',
  processMiddleware({
    storage: diskStorage
  }),
)

// Set the uploading image middleware
app.post(
  '/images',
  uploadMiddleware({
    storage: diskStorage,
  }),
)

app.listen(3000)

Middlewares

processMiddleware(options)

This middleware is used for search and process images. For processing and transforming images it uses sharp.

Example:

import { processMiddleware } from 'express-image-server'

const app = express()

app.get(
  '/images/:id',
  processMiddleware({
    storage: ...
  }),
)

app.listen(3000)

NOTE: This middleware expects an id in URL params. The id is the original name of the image in the storage.

With this middleware the route will accept request with the following structure:

           Express app        Endpoint      Image id              Operations
      ┌────────────────────┐┌──────────┐┌─────────────┐┌──────────────────────────────┐
GET   https://my-domain.com/path/images/image-name.png?height=720&width=1080&format=jpg

That request will process the image image-name.png with the operations and will return as response image-name.jpg in 1080x720 dimension. Also, it will save in the storage the image image-name,height-720,width-1080.jpg.

The following are the options that can be passed to processMiddleware: | Key | Description | Note | | --------- | ------------------------------------ | ------------------ | | storage | Where to search and store the images | An Storage class | | | |

This middleware follows the algorithm:

  1. Checks if the image processed with the operations asked already exist in the storage;
  2. If yes:
    1. Fetch the processed image;
    2. Return it in the response;
  3. If not:
    1. Fetch the original image (by the id URL param);
    2. Process the image with the operations asked;
    3. Save the processed image in the storage for future requests;
    4. Return it in the response;

Avaible image operations

| Query param name | Description | | ---------------- | --------------------- | | width | Output image's width | | height | Output image's height | | format | Output image format |

uploadMiddleware(options)

This middleware is used for uploading images direct to the storage and it is built on top of multer.

Example:

import { uploadMiddleware } from 'express-image-server'

const app = express()

app.post(
  '/images',
  uploadMiddleware({
    storage: ...,
  }),
)

app.listen(3000)

With this middleware the route will accept POST requests to save a single image at a time. To properly work, the request's body must be set as form-data and the image file must be sent in file parameter. The image will be sent to the storage with the file's name.

The following are the options that can be passed to uploadMiddleware: | Key | Description | Note | | --------- | ------------------------- | ------------------ | | storage | Where to store the images | An Storage class | | | |

NOTE: This middleware requires that the storage class used has the getMulterStorage function, which will be used to config multer internally.

Storages

Storages classes are responsible for the communication to the image storage, which means in general fetch and send images to it.

Storages classes implements Storage interface and expose four functions:

  • save: (id: string, image: Buffer) => Promise<boolean>
  • fetch: (id: string) => Promise<Buffer | undefined>
  • exists: (id: string) => Promise<boolean>
  • getMulterStorage?: () => multer.StorageEngine

NOTE: getMulterStorage function is set as optional, but it is mandatory when using uploadMiddleware. This happens because this function returns the multer storage config used by that middleware.

express-image-server provides two default storages: Disk Storage and Amazon S3 Storage.

Disk Storage

Searches and stores images in the hard disk.

import path from 'path'
import { DiskStorage } from 'express-image-server'

const destination = path.resolve(__dirname, '..', 'images')

const diskStorage = new DiskStorage({
  dest: destination,
})

For the multer config uses multer.DiskStorage engine.

Amazon S3 Storage

Searches and stores images in Amazon S3.

import { S3Storage } from 'express-image-server'

const s3Storage = new S3Storage({
  bucketName: 'bucket-name',
  accessKeyId: 'access-key-id',
  secretAccessKey: 'secret-access-key',
  region: 'region'
})

For the multer config uses multerS3 lib, that export an multer store engine for AWS S3.

Custom Storage

You can create your own custom storage class. You just have to define a class that implements the Storage interface. Check the example:

import { Storage } from 'express-image-server'

class MyCustomStorage implements Storage {
  constructor(/*{...your options}*/) {
    ...
  }

  async save(id: string, image: Buffer): Promise<boolean> {
    ...
  }

  async fetch(id: string): Promise<Buffer | undefined> {
    ...
  }

  async exists(id: string): Promise<boolean> {
    ...
  }

  getMulterStorage(): StorageEngine {
    ...
  }
}

To implement your own multer.StoreEngine or to see the standard ones, please check the multer's documentation.

License

MIT