# How do I set headers without returning response yet?

**URL:** <https://discourse.nodered.org/t/how-do-i-set-headers-without-returning-response-yet/26467>\
**Category:** General\
**Created:** [11 May 2020 08:05 UTC](https://discourse.nodered.org/t/how-do-i-set-headers-without-returning-response-yet/26467 "2020-05-11T08:05:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElleshaHackett](https://avatars.discourse-cdn.com/v4/letter/e/8c91f0/32.png) [@ElleshaHackett](https://discourse.nodered.org/u/ElleshaHackett)\
**Post date:** [11 May 2020 08:05 UTC](https://discourse.nodered.org/t/how-do-i-set-headers-without-returning-response-yet/26467/1 "2020-05-11T08:05:07Z")

</div>

I currently use `msg.res.set('x', 'x');` which works fine except for the deprecation warnings `"Deprecated call to msg.res.set"`. I could not find another way to do this without instantly returning response. What is the proper alternative?

I separely set the msg.statusCode and several headers on different places in the flow, all returning to the same output function that deals with those.

- `msg.res.set()` works but results in a deprecation warning
- `msg.res.header()` cannot be used: "TypeError: msg.res.header is not a function"
- `msg.res.headers['x'] = 'x'` or something like that seems not possible because that object is probably inside `_res` which is `[internal]`

Also [http://expressjs.com/en/5x/api.html#res.set](http://expressjs.com/en/5x/api.html#res.set) doesn't mention the deprecation of `.set` at all, so I don't understand why this would be deprecated in NodeRED.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [11 May 2020 08:16 UTC](https://discourse.nodered.org/t/how-do-i-set-headers-without-returning-response-yet/26467/2 "2020-05-11T08:16:17Z")

</div>

What are you trying to do?

statusCode is set after a request to tell you the status of your request - why on earth are you trying to set it?

As for headers, read the side bar help info - I think it tells you how to set them there.

---

<div class="post-metadata">

**Author:** ![ElleshaHackett](https://avatars.discourse-cdn.com/v4/letter/e/8c91f0/32.png) [@ElleshaHackett](https://discourse.nodered.org/u/ElleshaHackett)\
**Post date:** [11 May 2020 08:22 UTC](https://discourse.nodered.org/t/how-do-i-set-headers-without-returning-response-yet/26467/3 "2020-05-11T08:22:22Z")

</div>

StatusCode is not really relevant here yet. Basically I have a bunch of GET endpoints that do stuff while in the meanwhile adding (if needed) some response headers (sometimes many steps before it's ready to respond), that's exactly the purpose.

Then in the end they all reach the same "output" subflow which contains a few more `msg.res.set()` calls to add headers, respects the `statusCode` set by a previous fuction and basically ends the request with `http response node`. All works exactly a

Is expected except the deprecation warning is annoying.

In a nutshell: I need to simply set a simple response header before the `http response node` is called, kind of like middleware but without implementing the full middleware.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [11 May 2020 08:25 UTC](https://discourse.nodered.org/t/how-do-i-set-headers-without-returning-response-yet/26467/4 "2020-05-11T08:25:05Z")

</div>

> [@ElleshaHackett](#):
>
> Also [Express 5.x - API Reference](http://expressjs.com/en/5x/api.html#res.set) doesn't mention the deprecation of `.set` at all, so I don't understand why this would be deprecated in NodeRED.

What has been deprecated is a flow treating `msg.res` as a HttpResponse object and assuming it can use the functions provided by the express API. You should not be calling any of the functions on that object.

The sidebar help for the HTTP nodes describes how to set headers - create a property called `msg.headers` and add them to that. The HTTP Response node will use that property to set the headers of the response.

---

<div class="post-metadata">

**Author:** ![ElleshaHackett](https://avatars.discourse-cdn.com/v4/letter/e/8c91f0/32.png) [@ElleshaHackett](https://discourse.nodered.org/u/ElleshaHackett)\
**Post date:** [11 May 2020 08:35 UTC](https://discourse.nodered.org/t/how-do-i-set-headers-without-returning-response-yet/26467/5 "2020-05-11T08:35:55Z")

</div>

@knolleary exactly what I was looking for. Thanks. _I just expected that it the `express` way would make more sense._

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [25 May 2020 08:35 UTC](https://discourse.nodered.org/t/how-do-i-set-headers-without-returning-response-yet/26467/6 "2020-05-25T08:35:57Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
