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-adaptive-images

v0.10.0

Published

Connect/Express middleware for serving up adaptive images based on device width.

Readme

Adaptive Images for ExpressJS

Disclaimer about project

This module is 100% inspired by Matt Wilcox's PHP library, "Adaptive Images". It is not a one-to-one mapping in terms of features, but the general idea is the same.

This is a piece of middleware that can be used with Express and Connect.

Installation

$ npm install express-adaptive-images

Just like the PHP library you also need to add one line of Javascript to the <head> of your page to set a cookie on the browser/client side with the device's resolution.

<script>
  document.cookie='resolution='+Math.max(screen.width,screen.height)+("devicePixelRatio" in window ? ","+devicePixelRatio : ",1")+'; path=/';
</script>

Dependencies

Since a cookie is needed to know the device's resolution, it is required that you use cookie-parser middleware or any other alternative that would produce an object of cookies on req.cookies.

Internally express-adaptive-images also uses the gm library to resize the images, so you will need to have either GraphicsMagick or ImageMagick installed on your server. This is pretty easy, so I suggest you take a look here for instructions for your operating system.

By default GraphicsMagick is used by this module, or you can choose to use ImageMagick by setting the { useImageMagick: true } property as part of the options.

Usage

var adaptiveImages = require('express-adaptive-images');
var cookieParser = require('cookie-parser');
var express = require('express');

var app = express();
var defaultOptions = {
  imageTypes: [ '.jpg', '.png', '.jpeg', '.gif' ],
  breakpoints: [ 1382, 992, 768, 480 ],
  cachePath: 'ai-cache',
  watchCache: true,
  cachePeriod: 60 * 60 * 24 * 7, // 7 days in seconds
  setExpirationHeaders: true,
  useImageMagick: false,
  debug: false
};
var staticPath = __dirname + '/static';

app.use(cookieParser());
app.use(adaptiveImages(staticPath, defaultOptions));
app.use(express.static(staticPath));

Warning: express-adaptive-images should be used before any middleware that is serving files (e.g. express.static) so that they know to serve the new resized and cached files.

Overview

The first argument of express-adaptive-images (required) is the path to your static assets on the filesystem. It should generally be the same path that you pass to express.static. The second argument (optional) is an object of options (see the usage example for default values).