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

express-http-response

v0.0.8

Published

Node.js response middleware to provide a standard response output

Readme

express-http-response

NPM Version NPM Downloads Build Status Test Coverage MIT License

Node.js http response middleware to provide a standard response output.

Install

npm install --save http-response-middleware

Example

// # app.js
var express = require('express');
var httpResponse = require('express-http-response');

var BadRequestResponse = httpResponse.BadRequestResponse;
var OkResponse = httpResponse.OkResponse;
var app = express();

app.get('/users', function(req, res, next) {

    if (req.missing_parameter) {
        throw new BadRequestResponse('Missing required parameter.');
        /**
        which will return:
        Header status code: 400
        {
            type: "BadRequestResponse",
            message: "Missing required parameter.",
            status: 400,
            success: false
        }
        logging to console.error
        */
    }

    next(new OkResponse({
        users: { /* ... */ },
        page: 1,
        total: 42
    }));

    /**
    which will return:
    Header status code: 200
    {
        type: "OkResponse",
        message: "OK",
        status: 200,
        success: true,
        data: {
            users: { },
            page: 1,
            total: 42
        }
    }
    */

});

// keep this after all routes that will use the response object
app.use(httpResponse.Middleware);

app.listen(3000);

API

Middleware

The middleware will parse the thrown response returning to the user with a standard json response.

var httpResponse = require('express-http-response');
var express = require('express');
var app = express();

/** [app routes] */

app.use(httpResponse.Middleware);

HttpResponse

var HttpResponse = require('express-http-response').HttpResponse;

var response = new HttpResponse (data, message, httpStatusCode, errorCode, moreInfo, success);

/*
response == {
    type: "HttpResponse",     // String
    data: `data`,             // Mixed/Object | not present if undefined
    message: `message`,       // String
    status: `httpStatusCode`, // Int
    code: `errorCode`,        // Mixed/Object | not present if undefined
    moreInfo: `moreInfo`,     // Mixed/Object | not present if undefined
    success: `success`        // Boolean, false by default
}
*/

OkResponse

var OkResponse = require('express-http-response').OkResponse;

var response = new OkResponse (data, message, moreInfo);

/*
response == {
    type: "OkResponse",       // String
    data: `data`,             // Mixed/Object | not present if undefined
    message: `message`,       // String
    status: 200,              // Int
    moreInfo: `moreInfo`,     // Mixed/Object | not present if undefined
    success: true             // Boolean
}
*/

BadRequestResponse

var BadRequestResponse = require('express-http-response').BadRequestResponse;

var response = new BadRequestResponse (message, errorCode, moreInfo);

/*
response == {
    type: "BadRequestResponse", // String
    message: `message`,       // String
    status: 400,              // Int
    moreInfo: `moreInfo`,     // Mixed/Object | not present if undefined
    success: false            // Boolean
}
*/

UnauthorizedResponse

var UnauthorizedResponse = require('express-http-response').UnauthorizedResponse;

var response = new UnauthorizedResponse (message, errorCode, moreInfo);

/*
response == {
    type: "UnauthorizedResponse", // String
    message: `message`,       // String
    status: 401,              // Int
    moreInfo: `moreInfo`,     // Mixed/Object | not present if undefined
    success: false            // Boolean
}
*/

ForbiddenResponse

var ForbiddenResponse = require('express-http-response').ForbiddenResponse;

var response = new ForbiddenResponse (message, errorCode, moreInfo);

/*
response == {
    type: "ForbiddenResponse", // String
    message: `message`,       // String
    status: 403,              // Int
    moreInfo: `moreInfo`,     // Mixed/Object | not present if undefined
    success: false            // Boolean
}
*/

NotFoundResponse

var NotFoundResponse = require('express-http-response').NotFoundResponse;

var response = new NotFoundResponse (message, errorCode, moreInfo);

/*
response == {
    type: "NotFoundResponse", // String
    message: `message`,       // String
    status: 404,              // Int
    moreInfo: `moreInfo`,     // Mixed/Object | not present if undefined
    success: false            // Boolean
}
*/

MethodNotAllowedResponse

var MethodNotAllowedResponse = require('express-http-response').MethodNotAllowedResponse;

var response = new MethodNotAllowedResponse (message, errorCode, moreInfo);

/*
response == {
    type: "MethodNotAllowedResponse", // String
    message: `message`,       // String
    status: 405,              // Int
    moreInfo: `moreInfo`,     // Mixed/Object | not present if undefined
    success: false            // Boolean
}
*/

ConflictResponse

var ConflictResponse = require('express-http-response').ConflictResponse;

var response = new ConflictResponse (message, errorCode, moreInfo);

/*
response == {
    type: "ConflictResponse", // String
    message: `message`,       // String
    status: 409,              // Int
    moreInfo: `moreInfo`,     // Mixed/Object | not present if undefined
    success: false            // Boolean
}
*/

InternalServerErrorResponse

var InternalServerErrorResponse = require('express-http-response').InternalServerErrorResponse;

var response = new InternalServerErrorResponse (message, errorCode, moreInfo);

/*
response == {
    type: "InternalServerErrorResponse", // String
    message: `message`,       // String
    status: 500,              // Int
    moreInfo: `moreInfo`,     // Mixed/Object | not present if undefined
    success: false            // Boolean
}
*/

License

MIT