# Fetch Backend Data in Foreground

**URL:** <https://discourse.nodered.org/t/fetch-backend-data-in-foreground/73955>\
**Category:** Developing Nodes\
**Created:** [20 January 2023 11:19 UTC](https://discourse.nodered.org/t/fetch-backend-data-in-foreground/73955 "2023-01-20T11:19:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Flachmann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/flachmann/32/60457_2.png) [@Flachmann](https://discourse.nodered.org/u/Flachmann)\
**Post date:** [20 January 2023 11:19 UTC](https://discourse.nodered.org/t/fetch-backend-data-in-foreground/73955/1 "2023-01-20T11:19:58Z")

</div>

Hi,

I like to fetch an environment variable in `oneditsave()` and wonder if this is possible. I think that the problem is, that we're on the browser, but need to get data from the NR-flow.

Something like:

```auto
//...
oneditsave: function () {
	// ...
	const e = $env.get('VARIABLE');
	// ...
}

```

Is there a straightforward way?

---

<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:** [20 January 2023 11:58 UTC](https://discourse.nodered.org/t/fetch-backend-data-in-foreground/73955/2 "2023-01-20T11:58:52Z")

</div>

> [@Flachmann](#):
>
> Is there a straightforward way?

You can add an admin endpoint in node-red (server-side) (in the JS) and call it from the front end (in the html script).

Look at the source for the serial node (and others) that already do this.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [20 January 2023 12:15 UTC](https://discourse.nodered.org/t/fetch-backend-data-in-foreground/73955/3 "2023-01-20T12:15:55Z")

</div>

I'm on my lunch, so dropping by...

To enforce the above by @Steve-Mcl, here is what I do for my z-wave module:  
Here is an http endpoint, that returns serial ports :

> <https://github.com/zwave-js/node-red-contrib-zwave-js/blob/eb3fd712970524eedd6c0e995d41468bbb5814cd/src/nodes/ZWaveJSRuntime.ts#L893>

Then in my node html (`oneditprepare`)

> <https://github.com/zwave-js/node-red-contrib-zwave-js/blob/eb3fd712970524eedd6c0e995d41468bbb5814cd/build/nodes/ZWaveJSRuntime.html#L139>

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [20 January 2023 12:59 UTC](https://discourse.nodered.org/t/fetch-backend-data-in-foreground/73955/4 "2023-01-20T12:59:13Z")

</div>

uibuilder also has several examples and they are broken out into separate functions for convenience along with error handling and user-notification where needed.

---

<div class="post-metadata">

**Author:** ![Flachmann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/flachmann/32/60457_2.png) [@Flachmann](https://discourse.nodered.org/u/Flachmann)\
**Post date:** [20 January 2023 13:08 UTC](https://discourse.nodered.org/t/fetch-backend-data-in-foreground/73955/5 "2023-01-20T13:08:57Z")

</div>

Cool, works like charm. A little bit painful to search all these source code for solutions. 😉

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [20 January 2023 13:15 UTC](https://discourse.nodered.org/t/fetch-backend-data-in-foreground/73955/6 "2023-01-20T13:15:29Z")

</div>

Maybe fresh eyes could document it and submit a PR against the node-red docs? 😉

---

<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:** [3 February 2023 13:15 UTC](https://discourse.nodered.org/t/fetch-backend-data-in-foreground/73955/7 "2023-02-03T13:15:43Z")

</div>

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