Skip to content

Repository files navigation

send-data build status

send data through response

Originally taken from npm-www

Example

varsend=require("send-data")varsendJson=require("send-data/json")varsendHtml=require("send-data/html")varsendError=require("send-data/error")varhttp=require("http")http.createServer(functionhandleRequest(req,res){if(req.url==="/send"){send(req,res,{body: "foo",statusCode: 202,headers: {bar: "baz"}})}elseif(req.url==="/optional"){send(req,res,"foo")}elseif(req.url==="/json"){sendJson(req,res,{body: {foo: "bar"},statusCode: 201})}elseif(req.url==="/json/optional"){sendJson(req,res,{foo: "bar"})}elseif(req.url==="/html"){sendHtml(req,res,{body: "<div>foo</div>",statusCode: 200,headers: {}})}elseif(req.url==="/html/optional"){sendHtml(req,res,"<div>foo</div>")}elseif(req.url==="/oops"){sendError(req,res,{body: newError("OOPS")})}}).listen(8080)

Installation

npm install send-data

Tests

npm test

Contributors

  • Raynos

MIT Licenced

About

send data through response

Resources

Stars

26 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages