# \#javascript

**URL:** https://discourse.nodered.org/tag/javascript/43.md

[Latest](https://discourse.nodered.org/latest.md) · [Categories](https://discourse.nodered.org/categories.md) · [Tags](https://discourse.nodered.org/tags.md)

---

## [Javascript Not Running in ui\_template](https://discourse.nodered.org/t/javascript-not-running-in-ui-template/101712)

<div class="topic-metadata">

**Author:** [@TrickyZXR](https://discourse.nodered.org/u/TrickyZXR)\
**Replies:** 16\
**Last updated:** [2 September 2026 12:51 UTC](https://discourse.nodered.org/t/javascript-not-running-in-ui-template/101712 "2026-09-02T12:51:48Z")

</div>

I have a function to scan a dir in .node-red dir on rpi and give me a list of images in that dir. if (!msg.payload) return msg; // Split into lines let lines = msg.payload.split("\\\\n").filter(x =\> x.trim() !== ""); // B…

---

## [JavaScript Concepts](https://discourse.nodered.org/t/javascript-concepts/100206)

<div class="topic-metadata">

**Author:** [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Replies:** 0\
**Last updated:** [21 January 2026 13:51 UTC](https://discourse.nodered.org/t/javascript-concepts/100206 "2026-01-21T13:51:05Z")

</div>

This is a rather useful summary of key JavaScript concepts. A great resource for both fundamental learning and knowledge refreshment.

---

## [Linting and formatting](https://discourse.nodered.org/t/linting-and-formatting/93060)

<div class="topic-metadata">

**Author:** [@ThingsTinkerer](https://discourse.nodered.org/u/ThingsTinkerer)\
**Replies:** 23\
**Last updated:** [12 November 2024 09:37 UTC](https://discourse.nodered.org/t/linting-and-formatting/93060 "2024-11-12T09:37:04Z")

</div>

Any way to configure linting and formatting? Default is quite good, but always some annoyances. Examples: const payload = { ts: date.getTime(), values: data }; return {payload: payload}; "'payload' is declared…

---

## [Example complex function node to get and parse HTML email - using OutdoorActive weekly recommended routes](https://discourse.nodered.org/t/example-complex-function-node-to-get-and-parse-html-email-using-outdooractive-weekly-recommended-routes/90381)

<div class="topic-metadata">

**Author:** [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Replies:** 0\
**Last updated:** [23 August 2024 22:01 UTC](https://discourse.nodered.org/t/example-complex-function-node-to-get-and-parse-html-email-using-outdooractive-weekly-recommended-routes/90381 "2024-08-23T22:01:53Z")

</div>

Hi all, Here is an example of using a function node with some added Node.js modules to read emails via IMAP, sanitise and process the HTML content and extract details to a retained global variable. I use an Android app…

---

## [Red-ui-sidebar-shade hide, prevents added side bar to be clickable](https://discourse.nodered.org/t/red-ui-sidebar-shade-hide-prevents-added-side-bar-to-be-clickable/88961)

<div class="topic-metadata">

**Author:** [@bfany365](https://discourse.nodered.org/u/bfany365)\
**Replies:** 5\
**Last updated:** [26 June 2024 09:15 UTC](https://discourse.nodered.org/t/red-ui-sidebar-shade-hide-prevents-added-side-bar-to-be-clickable/88961 "2024-06-26T09:15:58Z")

</div>

Hi Reading RED.sidebar : Node-RED, I added a side bar and when I open that sidebar, the following html element is added to the sidebar html code: "\< div class="red-ui-sidebar-shade hide" style="display: block;"\>" Th…

---

## [Cleaner javascript code in function](https://discourse.nodered.org/t/cleaner-javascript-code-in-function/87059)

<div class="topic-metadata">

**Author:** [@KarolisL](https://discourse.nodered.org/u/KarolisL)\
**Replies:** 2\
**Last updated:** [7 April 2024 19:44 UTC](https://discourse.nodered.org/t/cleaner-javascript-code-in-function/87059 "2024-04-07T19:44:49Z")

</div>

I use a lot of functions in my flows and I've noticed that hardest thing is to write properly maintainable code. I came across this repository: I ask ChatGPT to adhere to these rules and it gives cleaner code. Any co…

---

## [Global Var in JSON](https://discourse.nodered.org/t/global-var-in-json/85286)

<div class="topic-metadata">

**Author:** [@gerand](https://discourse.nodered.org/u/gerand)\
**Replies:** 4\
**Last updated:** [7 February 2024 10:50 UTC](https://discourse.nodered.org/t/global-var-in-json/85286 "2024-02-07T10:50:01Z")

</div>

Hello, I would like to replace the injection nodes with a slider. To do this, I created a global variable “Slider”. How can I replace this with the fixed number 50 in JSON? I wanted to change this: to this: { "…

---

## [Using template node with if else condition](https://discourse.nodered.org/t/using-template-node-with-if-else-condition/85176)

<div class="topic-metadata">

**Author:** [@RudolfTheRedNode](https://discourse.nodered.org/u/RudolfTheRedNode)\
**Replies:** 10\
**Last updated:** [7 February 2024 03:29 UTC](https://discourse.nodered.org/t/using-template-node-with-if-else-condition/85176 "2024-02-07T03:29:08Z")

</div>

Hi All, I am developing a dashboard, but I want to hide the image in dashboard that is why I need to come up with this program that can hide the image using template node. Shown below is my code inside template node. B…

---

## [Neater way of checking ping results](https://discourse.nodered.org/t/neater-way-of-checking-ping-results/84343)

<div class="topic-metadata">

**Author:** [@AndrewBeasley](https://discourse.nodered.org/u/AndrewBeasley)\
**Replies:** 7\
**Last updated:** [7 January 2024 12:55 UTC](https://discourse.nodered.org/t/neater-way-of-checking-ping-results/84343 "2024-01-07T12:55:10Z")

</div>

Trying to get my head around Javascript and Node-Red this year and looking to use a bit more code rather than convoluted flows that stretch across the screen... I am using the ping function from node-red-node-ping to ch…

---

## [Formatting numbers the Right Way](https://discourse.nodered.org/t/formatting-numbers-the-right-way/83928)

<div class="topic-metadata">

**Author:** [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Replies:** 0\
**Last updated:** [21 December 2023 15:31 UTC](https://discourse.nodered.org/t/formatting-numbers-the-right-way/83928 "2023-12-21T15:31:56Z")

</div>

Node.JS and modern browsers all support the INTL library natively. That library has lots of features for formatting things to a locale specific format including dates and numbers. So here is a cheeky little JavaScript f…

---

## [Dynamic electricity supplier output in table format](https://discourse.nodered.org/t/dynamic-electricity-supplier-output-in-table-format/83365)

<div class="topic-metadata">

**Author:** [@KistK](https://discourse.nodered.org/u/KistK)\
**Replies:** 3\
**Last updated:** [2 December 2023 22:06 UTC](https://discourse.nodered.org/t/dynamic-electricity-supplier-output-in-table-format/83365 "2023-12-02T22:06:36Z")

</div>

Hi, I need some help. I'm relatively new to Node-RED. I found a flow that would be perfect for me. You can find it here: https://flows.nodered.org/flow/df892f62326e5dce5708b7512213ce24 This flow should output the hour…

---

## [Function node export object from start section](https://discourse.nodered.org/t/function-node-export-object-from-start-section/82049)

<div class="topic-metadata">

**Author:** [@dakhnod](https://discourse.nodered.org/u/dakhnod)\
**Replies:** 1\
**Last updated:** [15 October 2023 14:47 UTC](https://discourse.nodered.org/t/function-node-export-object-from-start-section/82049 "2023-10-15T14:47:08Z")

</div>

I use a function node to connect to socket.io, thus creating a socket object in the Start tab. I need access to that socket object in the Stop section, to close the connection again. Alternatively, node.on('close', ...…

---

## [Extracting Context Flow Array from Function Node](https://discourse.nodered.org/t/extracting-context-flow-array-from-function-node/80299)

<div class="topic-metadata">

**Author:** [@WillShiell](https://discourse.nodered.org/u/WillShiell)\
**Replies:** 2\
**Last updated:** [3 August 2023 21:44 UTC](https://discourse.nodered.org/t/extracting-context-flow-array-from-function-node/80299 "2023-08-03T21:44:14Z")

</div>

Hello I am running into issues attempting to extract my Context Array using the Function Node. Here is my Flow Context: And here is the function node code I am attempting to use to obtain the array value: let values…

---

## [Replacement for package "request-promise"?](https://discourse.nodered.org/t/replacement-for-package-request-promise/78347)

<div class="topic-metadata">

**Author:** [@cameo69](https://discourse.nodered.org/u/cameo69)\
**Replies:** 3\
**Last updated:** [11 May 2023 18:29 UTC](https://discourse.nodered.org/t/replacement-for-package-request-promise/78347 "2023-05-11T18:29:09Z")

</div>

I am looking for a replacement of the request-promise package that is deprecated. I tried axios and it generally works, but I am not 100% happy with it, especially because I am getting a strange error that is open on the…

---

## [Declaring array of objects in payload](https://discourse.nodered.org/t/declaring-array-of-objects-in-payload/77657)

<div class="topic-metadata">

**Author:** [@JesFo](https://discourse.nodered.org/u/JesFo)\
**Replies:** 3\
**Last updated:** [18 April 2023 05:24 UTC](https://discourse.nodered.org/t/declaring-array-of-objects-in-payload/77657 "2023-04-18T05:24:21Z")

</div>

Hello. I'm trying to declare an array of objects into my msg.payload using a JavaScript node. I declare my array as such: msg.payload = { DeviceID : '0', Sensors : \[\] } And th…

---

## [How can i change a variable with a payload](https://discourse.nodered.org/t/how-can-i-change-a-variable-with-a-payload/77188)

<div class="topic-metadata">

**Author:** [@DeWoAlliSeged7](https://discourse.nodered.org/u/DeWoAlliSeged7)\
**Replies:** 11\
**Last updated:** [3 April 2023 17:21 UTC](https://discourse.nodered.org/t/how-can-i-change-a-variable-with-a-payload/77188 "2023-04-03T17:21:15Z")

</div>

Hello I like to set a variable true or false if the payload from a device is true or false. In the moment I make the distinction in the python script. But I like to depend the message i send to the return message fr…

---

## [Change date/time format](https://discourse.nodered.org/t/change-date-time-format/76286)

<div class="topic-metadata">

**Author:** [@maru](https://discourse.nodered.org/u/maru)\
**Replies:** 5\
**Last updated:** [11 March 2023 17:15 UTC](https://discourse.nodered.org/t/change-date-time-format/76286 "2023-03-11T17:15:52Z")

</div>

Good morning all, I use this function node in my flow to check when my device sent the last data. var d = new Date(); var options = {year: 'numeric', month: '2-digit', day: '2-digit', hour: \`2-digit\`, minute: \`2-digit\`…

---

## [Help with error in function that...works!](https://discourse.nodered.org/t/help-with-error-in-function-that-works/76376)

<div class="topic-metadata">

**Author:** [@andre\_x](https://discourse.nodered.org/u/andre_x)\
**Replies:** 9\
**Last updated:** [10 March 2023 10:25 UTC](https://discourse.nodered.org/t/help-with-error-in-function-that-works/76376 "2023-03-10T10:25:29Z")

</div>

When I deploy Node Red says that there is an error in one of my function, this one: var timestamp = Date.now(); var disable\_notification\_until = global.get("disable\_notification\_until"); if (disable\_notification\_until \<=…

---

## [Getting several values from a string](https://discourse.nodered.org/t/getting-several-values-from-a-string/76242)

<div class="topic-metadata">

**Author:** [@DozoG](https://discourse.nodered.org/u/DozoG)\
**Replies:** 8\
**Last updated:** [10 March 2023 07:28 UTC](https://discourse.nodered.org/t/getting-several-values-from-a-string/76242 "2023-03-10T07:28:45Z")

</div>

Hi everyone, I have a tcp request node that returns a string containing a series of variables-value pairs: "!A00=0.25$!A04=228.00$!A22=2.00$" Each variable-value pair starts with ! and ends with $ In the example, the…

---

## [Try to convert msg.payload string of number into ascii](https://discourse.nodered.org/t/try-to-convert-msg-payload-string-of-number-into-ascii/75193)

<div class="topic-metadata">

**Author:** [@PhilLu](https://discourse.nodered.org/u/PhilLu)\
**Replies:** 13\
**Last updated:** [18 February 2023 12:51 UTC](https://discourse.nodered.org/t/try-to-convert-msg-payload-string-of-number-into-ascii/75193 "2023-02-18T12:51:29Z")

</div>

Hello, I have to translate a string of delimited numbers into ascii string. This is working fine: String.fromCharCode(65,66,67); // returns 'ABC' ... I have a msg.payload containing by example: 45,42,45,42,45,42,45,…

---

## [Function Node coding?](https://discourse.nodered.org/t/function-node-coding/75126)

<div class="topic-metadata">

**Author:** [@damica51](https://discourse.nodered.org/u/damica51)\
**Replies:** 6\
**Last updated:** [13 February 2023 19:13 UTC](https://discourse.nodered.org/t/function-node-coding/75126 "2023-02-13T19:13:58Z")

</div>

I'm sorry but I can't figure out how to code my function node. This is what I need to run. slope = 184.0 - 0.0 / 3730.0 - 746.0 offset = 0.0 - (slope \* 746.0) (msg.payload \* slope) + offset

---

## [Add an element on the go based on the value of msg.payload](https://discourse.nodered.org/t/add-an-element-on-the-go-based-on-the-value-of-msg-payload/73930)

<div class="topic-metadata">

**Author:** [@vongomben](https://discourse.nodered.org/u/vongomben)\
**Replies:** 3\
**Last updated:** [20 January 2023 19:33 UTC](https://discourse.nodered.org/t/add-an-element-on-the-go-based-on-the-value-of-msg-payload/73930 "2023-01-20T19:33:56Z")

</div>

Hi! Apologies in advance, this may sound a simple question. I would like to now how to create an element of msg.payload (or better, global.payload) based on the value of msg.payload. In other words: I am receiving a …

---

## [NR/MQTT and node 'function' to build modified payload](https://discourse.nodered.org/t/nr-mqtt-and-node-function-to-build-modified-payload/73728)

<div class="topic-metadata">

**Author:** [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Replies:** 6\
**Last updated:** [16 January 2023 06:40 UTC](https://discourse.nodered.org/t/nr-mqtt-and-node-function-to-build-modified-payload/73728 "2023-01-16T06:40:37Z")

</div>

Starting with NR is probably not as easy as I thought. While I have a (good) javascript background, I am at a loss here: Task: From a MQTT status query I get an object. From certain elements a new payload should be fo…

---

## [Use the Monaco editor in the dashboard UI?](https://discourse.nodered.org/t/use-the-monaco-editor-in-the-dashboard-ui/72991)

<div class="topic-metadata">

**Author:** [@Stwissel](https://discourse.nodered.org/u/Stwissel)\
**Replies:** 4\
**Last updated:** [5 January 2023 11:37 UTC](https://discourse.nodered.org/t/use-the-monaco-editor-in-the-dashboard-ui/72991 "2023-01-05T11:37:49Z")

</div>

I have an app that generates Json config files for another app. Currently I just curl the endpoint. What I’d like to do is to show them in the dashboard in a Monaco editor for further manual edit. Do we have a component …

---

## [Accessing Data from object that is in array(arrays again in object)](https://discourse.nodered.org/t/accessing-data-from-object-that-is-in-array-arrays-again-in-object/72861)

<div class="topic-metadata">

**Author:** [@Jhankhana](https://discourse.nodered.org/u/Jhankhana)\
**Replies:** 12\
**Last updated:** [30 December 2022 11:16 UTC](https://discourse.nodered.org/t/accessing-data-from-object-that-is-in-array-arrays-again-in-object/72861 "2022-12-30T11:16:39Z")

</div>

Hello, I am using http request to get data of one month. Screenshots of what I am getting in debug is attached below which is array of objects. Now I want to access minvalue from the first object and maxvalue from last …
