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

response-transformer

v0.7.1

Published

This package helps standardize REST API responses on NodeJS

Readme

Response Transformer

npm version GitHub license Build Status

Response Transformer helps you standardize your REST API response on NodeJS. It also comes with tons of response methods and functionalities with full Typescript support.

Getting started

Installation using npm

npm i response-transformer --save

Installation using yarn

yarn add response-transformer

Usage

ES5

const { okResponse, badRequestResponse } = require('response-transformer')

ES6

import { okResponse, badRequestResponse } from 'response-transformer'

Using with express

import express from 'express'
import { okResponse, badRequestResponse, validationError, sendResponse, statusCodes } from 'response-transformer'

const app = express()

app.get('/health-check', (request, response) => {
  return okResponse(response, 'Everything looks good', {
    name: 'Benjamin Iduwe',
    role: 'Software engineer',
  })
})

app.get('check', (request, response) => {
  return sendResponse(response, statusCodes.ACCEPTED, 'Received for processing')
})

app.get('check', (request, response) => {
  return validationError(response, 'Validation error', 'Name is required')
})

Returns

200: /health-check

{
    "status": true,
    "message": "Everything looks good",
    "data": {
        "name": "Benjamin Iduwe",
        "role": "Software engineer"
    }
}

202: /check

{
	"status": true,
	"message": "Received for processing",
}

422: /create

{
	"status": false,
	"message": "Validation error",
	"error": "Name is required",
}

Using HttpException to throw Http errors

import { HttpException, statusCodes } from 'response-transformer';

const getName = (name) => {
    if(! name){
        throw new HttpException('Name is invalid', statusCodes.NOT_FOUND);
    }
}

HttpException properties

  • Status code: The status code for the exception (error.statusCode).
  • shouldReport: Report only exception for server errors >= 500 (error.shouldReport)

Supported status codes

  • OK = 200.
  • CREATED = 201.
  • ACCEPTED = 202.
  • NO_CONTENT = 204.
  • BAD_REQUEST = 400.
  • PAYMENT_REQUIRED = 402.
  • UNAUTHORIZED = 401.
  • FORBIDDEN = 403,
  • NOT_FOUND = 404.
  • METHOD_NOT_ALLOWED = 405.
  • CONFLICT = 409.
  • UNPROCESSABLE_ENTITY = 422.
  • SERVER_ERROR = 500.
  • BAD_GATEWAY = 502.
  • SERVICE_UNAVAILABLE = 503.
  • GATEWAY_TIMEOUT = 504.

Supported frameworks

  1. Express
  2. NestJS
  3. AdonisJS
  4. SailJS

Available methods

okResponse(response, message, data);

createdResponse(response, message, data);

badRequestResponse(response, message, data);

unauthorizedResponse(response, message, data);

paymentRequiredResponse(response, message, data);

forbiddenResponse(response, message, data);

notFoundResponse(response, message, data);

methodNotAllowedResponse(response, message, data);

serverErrorResponse(response, message, data);

badGatewayResponse(response, message, data);

serviceUnavailableResponse(response, message, data);

sendResponse(response, statusCode, message, data);

Test

npm run test