Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

api-stds

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-stds

Standardized API response and error handling toolkit with async handler, requestId, logging, and configurable formats.

Source
npmnpm
Version
1.2.3
Version published
Weekly downloads
9
Maintainers
1
Weekly downloads
 
Created
Source

api-stds

A lightweight toolkit for standardizing API responses and improving developer experience in Node.js applications.
Includes async handler, configurable response formats, error normalization, request ID injection, and more, all customizable with api-stds.config.json.

Features

  • ⚡ Async handler, no more try/catch boilerplate.
  • 📦 Standardized responses, consistent success/error payloads.
  • 🛠 Config-driven, customize behavior via api-stds.config.json.
  • 🆔 Request ID support, opt-in correlation IDs for debugging.
  • 📜 Error normalization, unify error shapes.
  • 🔧 CLI, quick project setup via npx api-stds init.

Installation

npm i api-stds

Initialization

Run once per project:

npx api-stds init

This will:

  • Create a api-stds.config.json
  • Prompt you for features (e.g. enable requestId)
  • Install api-stds if not already installed

Example Usage

Express Example

import express from "express";
import { asyncHandler, stdResponse } from "api-stds";

const app = express();

app.get(
  "/user",
  asyncHandler(async (req, res) => {
    const user = { id: 1, name: "Captain" };
    res.json(stdResponse.success(user));
  })
);

app.get(
  "/error",
  asyncHandler(async () => {
    throw new Error("Something went wrong!");
  })
);

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

Example Success Response

{
  "status": "success",
  "data": {
    "id": 1,
    "name": "Captain"
  },
  "requestId": "3f2d8a17-9d34-4c8c-8f2b-9a123c4c5a90"
}

Example Error Response

{
  "status": "error",
  "message": "Something went wrong!",
  "code": "INTERNAL_SERVER_ERROR",
  "requestId": "3f2d8a17-9d34-4c8c-8f2b-9a123c4c5a90"
}

Configuration

api-stds.config.json (auto-generated with npx api-stds init):

{
  "useRequestId": true,
  "responseFormat": {
    "successKey": "data",
    "errorKey": "message",
    "includeTimestamp": true
  }
}

Scripts

npm run build     # compile TypeScript → dist
npm run test      # run unit tests
npm run lint      # lint with ESLint
npm run format    # format with Prettier

Keywords

api

FAQs

Package last updated on 22 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts