Sending Response
You have already seen the send()
method in action, when sending simple responses in some earlier examples in this chapter. The send()
method can use one of the following formats, where status
is the HTTP status code and body
is a String
or Buffer
object:
res.send(status, [body])res.send([body])
If you specify a Buffer
object, the Content-Type
is automatically set to application/octet-stream
unless you explicitly set it to something else. For example:
res.set('Content-Type', 'text/html');res.send(new Buffer('<html><body>HTML String</body></html>'));
The send()
method can really handle all the responses necessary, as long as you set the appropriate headers and status for the response. Once the send() ...
Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.