Response Helper for node.js projects


1.0.14 years ago4 years agoMinified + gzip package size for @dsninjas/response in KB



Response Helpers for node.js projects

This module makes it easy to format your response in node.js applications.


  • Make sure that Node.js installed.
  • Install Node.js library with npm:
    npm install @dsninjas/response
  • You can also install Node.js library with yarn:
    yarn add @dsninjas/response



The constructor helps you configure the response helper class.

const responseHelper = new ResponseHelper(Raven);

The constructor takes the following options:

  1. constructor(Raven) (required): this is a refernce to the global Raven object.

json(status, res, message, data, meta)

This method helps you format your json response.

const responseHelper = new ResponseHelper(Raven);
const status = 200;
const message = 'Success';
const data = {};
responseHelper.json(status, res, message, data);
  1. status (required): this is the status of the response.
  2. res (required): this is the response object.
  3. message (required): this is the message of the response.
  4. data (optional): this is the data with the response.
  5. meta (optional): this is the meta data with the response.

error(err, res)

This method helps you to format your error.

const responseHelper = new ResponseHelper(Raven);
responseHelper.error(err, res);
  1. err (required): this is the error object.
  2. res (required): this is the response object.

customError(res, data)

This method helps you to generate the token.

const responseHelper = new ResponseHelper(Raven);
responseHelper.customError(res, data);
  1. res (required): this is the response object.
  2. data (optional): this is the data with the response.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.