New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

sw-json

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sw-json

Convenience middleware for sending JSON

latest
Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
3
200%
Maintainers
1
Weekly downloads
 
Created
Source

sw-json

Convenience middleware for sending JSON. Adds a .json() method to the res object which responds with a JSON body.

Install

npm install sw-json

Example

var json = require('sw-json');

// With express
app.use(json);

var NOTFOUND = JSON.stringify({error: 'NOT_FOUND'});
// or use as inline middleware
app.get('/example/page', json, function(req, res) {
	if(req.query.n) {
		res.json(NOTFOUND, 404);  // Send a pre-serialized string
	} else {
		res.json({data: 'stuff'}); // or a JS object
	}
});

API

res.json(body, [code])

  • body - JavaScript object or JSON formatted string
  • code - Status code, optional, defaults to 200

Keywords

json

FAQs

Package last updated on 06 Jul 2015

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