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 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-timeout-header

v1.1.5

Published

Express middleware for handling HTTP 'Timeout' header (wait until file exists before 404)

Downloads

1

Readme

Express Middleware for HTTP "Timeout" Header

This module implements my proposal for an HTTP Timeout header (see also this blog post), indicating to a server that if a file doesn't exist, it should watch for it until the timeout expires. This allows clients to request files that they know will exist soon (like MPEG-DASH segments during live streaming) and receive them immediately after they are created.

Warning: Due to limitations in Node.js's fs.watch, we can't tell when a writer finishes writing a file. If you use this module, you should atomically move files into the folder (using rename for example). In future versions I intend to fix this by using inotify directly and waiting for IN_WRITE_CLOSE.

Installing

npm install express-timeout-header

Example

var express = require("express");
var expressTimeout = require("express-timeout-header");

var staticFolder = "static";
var port = 8080;

var app = express;
app.use(expressTimeout(staticFolder));
app.use(express.static(staticFolder));
app.listen(port);

Note that the timeout header middleware should generally come before any static file servers, since all the middleware does is hold onto the request until the requested file appears or the timeout expires.

Specifically, the API is:

expressTimeout(rootDirectory, options = {etag = false, indexes = ["index.html"], maxTimeout = 60000})

  • rootDirectory - The root directory to serve files from. Should be the same as your static file server's root directory.
  • etag - Set to true to wait until etag changes before sending existing file.
  • indexes - List of files to watch when a directory is requested.
  • maxTimeout - The maximum time to wait for a file to appear (in milliseconds). The actual timeout will be min(maxTimeout, request.headers.timeout).

Here's an example setting the maximum timeout to 10 seconds, turning on etag behavior, and watching for both "index.html" and "index.htm":

var indexes = ["index.html", "index.htm"];
app.use(expressTimeout(staticFolder, {etag: true, index: indexes, maxTimeout: 10000}));
app.use(express.static(staticFolder, {index: indexes);

For etags, etag(fstat) is used in order to match send's behavior ("send" is the module Express's static middleware uses for etags).

See this repo for a more complete example (in CoffeeScript).