Just started playing with Node.js and after seeing a few examples I see that usually the Content-Type
is set before returning some content.
Usually somethin
If you're using Express within your node app, then response.send(v)
will implicitly pick a default content-type depending on the runtime type of v
. More specifically, the behavior of express.Response.send(v)
is as follows:
v
is a string (and no content-type has already been set) then send Content-Type: text/html
v
is a Buffer (and no content-type has already been set) then send Content-Type: application/content-stream
v
is any other bool/number/object
(and no content-type has already been set) then send Content-Type: application/json
Here's the relevant source code from Express: https://github.com/expressjs/express/blob/e1b45ebd050b6f06aa38cda5aaf0c21708b0c71e/lib/response.js#L141