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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@saas-power-factory/express-response-kit

v0.1.1

Published

Tiny helper to send consistent API responses (status, message, data, error)

Downloads

7

Readme

@saas-power-factory/response-kit

Tiny Express helper to send consistent API responses with configurable required keys and default envelopes.

Quick Start

import express from 'express'
import { sendResponse, defaultMiddleware } from '@saas-power-factory/response-kit'

const app = express()
app.use(express.json())

// Option 1: Direct helper (no middleware needed)
app.get('/simple', (req, res) => {
  sendResponse(res, { status: 200, message: 'ok', data: { hello: 'world' } })
})

// Option 2: Use middleware to attach res.api.send
app.use(defaultMiddleware)
app.get('/middleware', (req, res) => {
  res.api.send({ status: 200, message: 'ok', data: { hello: 'world' } })
})

Configurable Response Kit

Create a configured response helper that ensures required keys are always present:

import { createResponseKit } from '@saas-power-factory/response-kit'

const { sendResponse, middleware } = createResponseKit({
  requiredKeys: ['status', 'message', 'error'],
  defaultEnvelope: { message: 'default message' },
  defaultStatus: 200
})

app.use(middleware)

app.get('/api/data', (req, res) => {
  // Only provide data - required keys will be filled automatically
  res.api.send({ data: { items: [] } })
  // Result: { status: 200, message: 'default message', error: null, data: { items: [] } }
})

app.get('/api/replace', (req, res) => {
  // Replace mode: custom payload replaces defaults but required keys are ensured
  sendResponse(res, { status: 201, custom: 'field' }, { replace: true })
  // Result: { status: 201, message: null, error: null, custom: 'field' }
})

Features

  • Consistent shape: All responses follow the same JSON structure
  • Required keys: Ensure specific fields are always present
  • Default values: Set fallback values for common fields
  • Replace mode: Option to override default envelope completely
  • TypeScript friendly: Proper types, no as any needed
  • Flexible: Accept custom fields alongside standard ones