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

@goelharshit006/api-kit

v1.0.2

Published

Production-ready API utilities and middleware toolkit for Express.js

Readme

@goelharshit006/api-kit

npm version npm downloads license node

Production-ready API utilities and middleware toolkit for Express.js.


Features

  • Standardized API responses
  • Centralized error handling
  • Async route handler wrapper
  • Response helper methods
  • Production-safe error responses
  • Pagination utilities
  • Query builder utilities
  • Field filtering utility
  • Lightweight and dependency-free

Installation

npm install @goelharshit006/api-kit

Quick Start

import express from "express";

import {
  asyncHandler,
  errorHandler,
  responseEnhancer,
  notFoundHandler,
  ApiError,
} from "@goelharshit006/api-kit";

const app = express();

app.use(express.json());

app.use(responseEnhancer);

app.get(
  "/",
  asyncHandler(async (req, res) => {

    return res.success(
      {
        name: "Harshit",
      },
      "API working"
    );

  })
);

app.get(
  "/error",
  asyncHandler(async (req, res) => {

    throw new ApiError(
      404,
      "User not found",
      "USER_NOT_FOUND"
    );

  })
);

app.use(notFoundHandler);

app.use(errorHandler);

app.listen(3000, () => {
  console.log("Server running on port 3000");
});

API Reference


ApiError

Create structured API errors.

throw new ApiError(
  404,
  "User not found",
  "USER_NOT_FOUND"
);

Parameters

| Parameter | Type | Default | | ---------- | ------ | --------------------- | | statusCode | number | 500 | | message | string | Something went wrong | | code | string | INTERNAL_SERVER_ERROR | | details | any | null |


asyncHandler

Wrap async Express controllers.

app.get(
  "/users",
  asyncHandler(async (req, res) => {

    const users = [];

    return res.success(users);

  })
);

responseEnhancer

Adds helper methods to the Express response object.

app.use(responseEnhancer);

Available Methods


res.success()

return res.success(
  data,
  "Success message"
);

res.fail()

return res.fail(
  "Request failed",
  400,
  "REQUEST_FAILED"
);

res.created()

return res.created(
  data,
  "Resource created"
);

res.noContent()

return res.noContent();

errorHandler

Global error handling middleware.

app.use(errorHandler);

Features

  • Handles custom ApiError instances
  • Handles unknown errors
  • Shows stack traces in development
  • Hides sensitive errors in production

notFoundHandler

Handles unknown routes.

app.use(notFoundHandler);

Utilities


getPaginationMeta()

Generate pagination metadata.

import {
  getPaginationMeta,
} from "@goelharshit006/api-kit";

const meta = getPaginationMeta({
  page: 1,
  limit: 10,
  totalItems: 95,
});

Example Output

{
  "page": 1,
  "limit": 10,
  "totalItems": 95,
  "totalPages": 10,
  "hasNextPage": true,
  "hasPrevPage": false
}

buildQueryOptions()

Parse query parameters safely.

import {
  buildQueryOptions,
} from "@goelharshit006/api-kit";

const options = buildQueryOptions(req.query);

Example Output

{
  page: 1,
  limit: 10,
  skip: 0,
  sort: "-createdAt",
  search: "",
}

pickFields()

Filter allowed fields from objects.

import {
  pickFields,
} from "@goelharshit006/api-kit";

const filteredBody = pickFields(
  req.body,
  ["name", "email"]
);

Production Ready

  • Environment-aware error handling
  • Stack traces hidden in production
  • Lightweight architecture
  • Clean and scalable structure

License

MIT


Author

Harshit


Support

If you like this package, consider giving the repository a star.