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

biscuits-send

v1.0.3

Published

A minimal and high-performance send response for Biscuit framework.

Readme

responseHandler Module

This module provides a simple and efficient way to handle HTTP responses in a Node.js application. It handles various data types (e.g., JSON, plain text, binary) and manages headers, content types, and status codes automatically.

Installation

To use this module in your Node.js application, simply require it in your project:

const responseHandler = require('./responseHandler');

Usage

The responseHandler function is designed to be used within a server response flow. It accepts the following parameters:

responseHandler(res, code, data, headers);

Parameters:

res (required): The HTTP response object (res), which is passed into the request handler.

code (optional): The HTTP status code (default is 200).

data (optional): The response data, which can be a string, object, Buffer, or Stream (default is '').

headers (optional): An object containing additional headers to be set in the response.

Example Usage:

const http = require('http');
const responseHandler = require('./responseHandler');

const server = http.createServer((req, res) => {
  const data = { message: 'Hello, world!' };
  responseHandler(res, 200, data, { 'X-Custom-Header': 'Some Value' });
});

server.listen(3000, () => {
  console.log('Server is running on port 3000');
});

In this example:

The server responds with a JSON object.

The 200 status code is used.

A custom header X-Custom-Header is included.

Detailed Explanation

  1. Validation of Status Code: The function checks if the provided status code is valid based on the STATUS_CODES from the built-in http module.

  2. Headers Normalization: All headers are converted to lowercase keys to ensure consistency. This allows for case-insensitive access to headers.

  3. Content-Type Handling:

If the data is a Promise, it waits for it to resolve.

If data is a Stream, it pipes the data directly to the response object.

If data is a Buffer or object, it appropriately sets the Content-Type header to application/octet-stream or application/json.

If the data is a string, it sets the Content-Type to text/plain by default.

  1. Error Handling: If an error occurs while piping a Stream, the server responds with a 500 Internal Server Error message.

  2. Content-Length Calculation: The Content-Length header is automatically calculated based on the data type:

If the data is a Buffer, its length is used.

If the data is a string or JSON, the byte length of the string is used.

  1. Sending the Response: The function sets the appropriate status code, headers, and sends the response data using res.writeHead() and res.end().

Supported Data Types

Buffer: The data is assumed to be binary data and the Content-Type is set to application/octet-stream.

Object: The data is automatically serialized to JSON and the Content-Type is set to application/json;charset=utf-8.

String: The data is sent as plain text with Content-Type: text/plain.

Stream: If data is a stream, it is piped directly to the response.

Error Handling

If an invalid status code is provided, an error will be thrown:

throw new Error(`Invalid status code: ${code}`);

Additionally, if there is an error while piping the Stream, the response is set to 500 Internal Server Error.

License

MIT License. See the LICENSE file for more details.