Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Express 4.x uses res.set instead of res.setHeader #21

Closed
shane-tomlinson opened this issue Jun 7, 2014 · 3 comments
Closed

Express 4.x uses res.set instead of res.setHeader #21

shane-tomlinson opened this issue Jun 7, 2014 · 3 comments

Comments

@shane-tomlinson
Copy link
Contributor

See http://expressjs.com/api.html#res.set

@elf-pavlik
Copy link

also

'app.router' is deprecated!

while examples in README use it

@troygoode
Copy link
Member

thanks for the heads up @shane-tomlinson and @elf-pavlik

mycrobe pushed a commit to warelab/gramene-swagger that referenced this issue Feb 25, 2016
… not a function"}` issue I don't fully understand but is kinda-sorta mentioned here: expressjs/cors#21
@markstos
Copy link

Express 4 inherits in the HTTP ServerResponse prototype:

var res = Object.create(http.ServerResponse.prototype)

Which means that all the methods available on HTTP ServerResponse class are available on the Express response object. This includes the setHeader method:

https://nodejs.org/api/http.html#http_response_removeheader_name

This is documented in the opening stanza of the Express "Response" object:

The res object is an enhanced version of Node’s own response object and supports all built-in fields and methods.

And it links to the docs for the "HTTP ServerResponse" class from there.

So, both res.setHeader() and res.set() officially work in Express 4.

res.setHeader() will perform slightly better, since res.set() is just a wrapper which calls res.setHeader().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants