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

@kikobeats/set-content-type

v1.0.9

Published

Set the HTTP response Content-Type by sniffing payload bytes with file-type / magic detection.

Readme

@kikobeats/set-content-type

Last version Coverage Status NPM Status

Set the response content-type based on the payload bytes.

Some upstreams (e.g. S3/CloudFront origins) stream a response without a content-type header. When you proxy those bytes, the browser can't tell it's an image and renders it as raw text — worse if you send x-content-type-options: nosniff.

This module fixes that: pipe the payload through it and, only when the response doesn't already have a content-type, it detects the type from the first bytes (via file-type) and sets it on the response before anything is written.

Install

$ npm install @kikobeats/set-content-type --save

Usage

Insert it between your upstream and the response:

const setContentType = require('@kikobeats/set-content-type')

server.on('request', (req, res) => {
  upstream.pipe(setContentType(res))
})

The returned stream is already wired to res, so you only pipe once. If the upstream already provided a content-type, it is left untouched.

API

setContentType(res)

res

Required Type: http.ServerResponse

The outgoing response whose content-type should be set when missing.

It returns a writable stream already piped to res — pipe your upstream into it and you are done.

The header is always set before the first byte is written to res, and an existing content-type is never overridden. Detection is delegated to fileTypeStream, which holds a sample before deciding, so a signature split across chunk boundaries is still recognized and a container reports its real type rather than its envelope — a .docx as a Word document rather than application/zip.

Buffering is bounded by that sample and nothing beyond it is held, so a body smaller than the sample reaches res when the upstream ends. Nothing is sampled at all when res already has a content-type.

If detection itself fails, the error surfaces on the returned stream and res is destroyed rather than sent a body the sample has already eaten into.

The header is not set when:

  • res already has a content-type header.
  • the response has already been sent (res.headersSent).
  • the payload type can not be recognized.

License

@kikobeats/set-content-type © Kiko Beats, released under the MIT License. Authored and maintained by Kiko Beats with help from contributors.

kikobeats.com · GitHub Kiko Beats · Twitter @kikobeats