New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jsender

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsender

Simple and structured application level JSON responses for Express. Based on JSend specification.

  • 0.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

JSender

Build Status

Simple and structured application level JSON responses for Express. Based on JSend specification (http://labs.omniti.com/labs/jsend).

Installation

npm install jsender

Setup the middleware in your Express app. Before any routes.

var express = require('express')
  , jsender = require('jsender')
  ;

var app = express();

// ... (other middlewares)
app.use(jsender());

app.get('/', function (req, res){
  res.success({
    notice: 'Hello, World!'
  });
});

// JSON Response
// {
//   "status": "success",
//   "data": {
//     "notice": "Hello, World!"
//   }
// }

API

JSender augments the node res object with the following methods.

success(data)

  • data: Optional response data object.
function (req, res){
  res.success({
    notice: 'Hello, World!'
  });
};

// JSON Response
// {
//   "status": "success",
//   "data": {
//     "notice": "Hello, World!"
//   }
// }

fail(data)

  • data: Required failure data.
function (req, res){
  res.fail({
    name: 'Name is required.'
  });
};

// JSON Response
// {
//   "status": "fail",
//   "data": {
//     "name": "Name is required."
//   }
// }

error(message, data, code)

  • message: Required error message.
  • data: Optional error data.
  • code: Optional error code.
function (req, res){
  res.error('Server error.');
};

// JSON Response
// {
//   "status": "error",
//   "message": "Server error."
// }

jsend(err, data)

  • err: An error object or null.
  • data: Optional response data object.
function (req, res){
  books.find()
    .exec(res.jsend);
};

// same as

function (req, res){
  books.find()
    .exec(function (err, data){
      if (err)
        return res.jsend(err);

      res.jsend(null, data);
    });
};

Keywords

FAQs

Package last updated on 24 Aug 2014

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc