View JS Express response headers?

If I need to see the headers of incoming requests, I use: req.headers.

I need to see a list of all the headers that will be in the response.

res.headers undefined.

I know that I can set the response headers: res.header('', '').

How to view response headers ..?

+4
source share
3 answers

The latest versions of the expression have:

res.getHeaders()

 -> {x-powered-by: "Express"}

Properties starting with "_" are not part of the official api. In case of changes, they will not be documented, and the likelihood that the code will break.

+4
source

Thanks @ nem035 .

Answer headers: res.header()._headers

+9
source

:

res.get('Content-Type');
// => "text/plain"

https://expressjs.com/en/api.html#res.get

, , :

res.get('content-type');
// => "text/plain"

res.getHeaders()['content-type']
// => "text/plain"
+1

All Articles