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

@ceicc/range

v3.0.2

Published

http range request handler

Downloads

26

Readme

Range

Middleware for serving static files

NPM Downloads per month Module type

Installation

npm i @ceicc/range

Usage

add range to an existence express app

import { range } from "@ceicc/range"

app.get('/public/*', range())

app.listen(3000)

This will serve every request starts with /public/ with range.

The base directory will be . or the current working directory, unless specified in the options object.

Options Object

maxAge

  • default: 10800
  • type: number

caching period in seconds.

etag

  • default: true
  • type: boolean

add Etag header.

lastModified

  • default: true
  • type: boolean

add last-modified header.

conditional

  • default: true
  • type: boolean

whether to respect conditional requests or not.

range

  • default: true
  • type: boolean

accept range request.

notFound

  • default: true
  • type: boolean|string

a handler for non existing files

notFound: false next will be called.

notFound: true empty body with status code '404' will be sent.

notFound: <string> send a file with status code '404', the given string is the path to file.

if the path doesn't led to a file, next will be called.

Note: The path is relative to the baseDir path.

implicitIndex

  • default: true
  • type: boolean|Array<string>

Check for index files if the request path is a directory.

Pass an array of extensions to check against. e.g. ["html", "css"]

Or simply pass true to check for html extension only.

baseDir

  • default: '.'
  • type: string

the base dirctory.

hushErrors

  • default: false
  • type: boolean

Whether to ignore errors and reply with status code 500, or pass the error to next function.

trailingSlash

  • default: true
  • type: boolean

Redirect directory requests to add trailing slash.

disabling this option will led to relative path issues. see #9

implicitIndex must be true

compression

  • default: false
  • type: false|Array<string>

Compress the response body with one of the compression algorithm given in the array.

availabel compression methods are:

  1. "br"
  2. "gzip"
  3. "deflate"

the compression method will be determined based on the request's accept-encoding header using npm package negotiator.

dateHeader

  • default: true
  • type: boolean

send date response header, new Date().toUTCString() function will be used to get the current date.

learn more about the date header

Real World Example

import { fileURLToPath } from "node:url"
import { join, dirname } from "node:path"
import express from "express"
import { range } from "@ceicc/range"

const app = express()

const __dirname = dirname(fileURLToPath(import.meta.url))

app.get('*', range({ baseDir: join(__dirname, "public") }))

app.use((error, req, res, next) => {
  console.error(error)
  res.sendStatus(500)
})

app.listen(3000, () => console.log("server listening on http://localhost:3000"))