Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

send-data

Raynos8.7k8.0.0

send data through response

readme

send-data build status

send data through response

Originally taken from npm-www

Example

var send = require("send-data")
var sendJson = require("send-data/json")
var sendHtml = require("send-data/html")
var sendError = require("send-data/error")
var http = require("http")

http.createServer(function handleRequest(req, res) {
    if (req.url === "/send") {
        send(req, res, {
            body: "foo",
            statusCode: 202,
            headers: {
                bar: "baz"
            }
        })
    } else if (req.url === "/optional") {
        send(req, res, "foo")
    } else if (req.url === "/json") {
        sendJson(req, res, {
            body: {
                foo: "bar"
            },
            statusCode: 201
        })
    } else if (req.url === "/json/optional") {
        sendJson(req, res, {
            foo: "bar"
        })
    } else if (req.url === "/html") {
        sendHtml(req, res, {
            body: "<div>foo</div>",
            statusCode: 200,
            headers: {}
        })
    } else if (req.url === "/html/optional") {
        sendHtml(req, res, "<div>foo</div>")
    } else if (req.url === "/oops") {
        sendError(req, res, { body: new Error("OOPS") })
    }
}).listen(8080)

Installation

npm install send-data

Tests

npm test

Contributors

  • Raynos

MIT Licenced

changelog

v3.0.5

  • update send-data/error to pass extra error objects through down the wire.

v3.0.4

  • throw an exception if you had { gzip: true } and no callback
  • set the gzip header

v3.0.0

Added gzip support and a callback interface

Back compat breaking changes

  • sendJson is now sendJson(req, res, opts) instead of sendJson(req, res, data, opts)

Summary

  • add callback to all methods. This gets called when the response finishes or if gzip errors
  • add gzip option to everything
  • fix bug with error's handling of sendObject

v2.2.1 Initial version