res.send()
Sends an HTTP response of various body types and ends the response.
Syntax
res.send([body]) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
body | string | object | Buffer | array | No | The response body. Strings send as HTML, objects/arrays as JSON, Buffers as binary. |
Returns
Response — The response object.
Examples
app.get('/', (req, res) => {
res.send('<h1>Hello</h1>');
});
Output
$ curl localhost:3000/
<h1>Hello</h1>
app.get('/data', (req, res) => {
res.send({ ok: true });
});
Output
{"ok":true}
Notes
Auto-sets `Content-Type` and `Content-Length` and ends the response.
Passing an object/array delegates to `res.json`. Call it (or another
terminal method) exactly once - a second send throws
`ERR_HTTP_HEADERS_SENT`.