Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 75dbe502f6
Fetching contributors…

Cannot retrieve contributors at this time

56 lines (44 sloc) 1.452 kB
section
h3(id='res.send') res.send([body|status], [body])
p.
Send a response.
+js.
res.send(new Buffer('whoop'));
res.send({ some: 'json' });
res.send('<p>some html</p>');
res.send(404, 'Sorry, we cannot find that!');
res.send(500, { error: 'something blew up' });
res.send(200);
p.
This method performs a myriad of
useful tasks for simple non-streaming responses such
as automatically assigning the Content-Length unless
previously defined and providing automatic <em>HEAD</em> and
HTTP cache freshness support.
p.
When a <code>Buffer</code> is given
the Content-Type is set to "application/octet-stream"
unless previously defined as shown below:
+js.
res.set('Content-Type', 'text/html');
res.send(new Buffer('<p>some html</p>'));
p.
When a <code>String</code> is given the
Content-Type is set defaulted to "text/html":
+js.
res.send('<p>some html</p>');
p.
When an <code>Array</code> or <code>Object</code> is
given Express will respond with the JSON representation:
+js.
res.send({ user: 'tobi' })
res.send([1,2,3])
p.
Finally when a <code>Number</code> is given without
any of the previously mentioned bodies, then a response
body string is assigned for you. For example 200 will
respond will the text "OK", and 404 "Not Found" and so on.
+js.
res.send(200)
res.send(404)
res.send(500)
Jump to Line
Something went wrong with that request. Please try again.