Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including send-json with all npm packages installed. Try it out:

var sendJson = require("send-json")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

send-json v2.0.0

Send JSON over http

send-json

build status

Send objects as JSON over http.

Example

var http = require('http');
var sendJson = require('send-json');

var server = http.createServer(function(req, res) {
  sendJson(req, res, {hello: 'world'});
});

server.listen(3000);

Or you can just add a send function to the http response object like this.

var http = require('http');
var sendJson = require('send-json');

var server = http.createServer(function(req, res) {
  res.send = sendJson.bind(null, req, res);

  res.send({hello: 'world'});
});

server.listen(3000);

License

MIT License

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free