IMD SolutionComputing LibraryShop main store

Troubleshooting

Why Node-RED flow import fails with config.forEach is not a function

Edge computing and IIoT Published 4 min read By IMD Solution engineering team

Short answer

Windows Command Prompt passes single quotes through to curl, so the header in your POST never names a JSON content type and Node-RED cannot parse the body: that is the config.forEach error, and the same split makes curl try to resolve application as a host. Send the file with double quotes around the header and the binary data option, keep http on the local port, and confirm the import with a GET of the active flows.

On this page
  1. Two errors from one command line
  2. How Command Prompt splits the line
  3. The corrected import
  4. Keep the import on HTTP
  5. Verify the import
  6. Scripting the deployment
  7. Questions asked

Your export is already a valid JSON array and your Node-RED instance answers, so neither is the fault: Windows Command Prompt breaks the line. It does not treat single quotes as quoting, so curl receives the header in -H 'content-type: application/json' as two separate words. The POST goes out without a usable Content-Type, Node-RED hands the handler an unparsed body, and the reply is config.forEach is not a function; the leftover word is then taken as a second URL, which is where could not resolve host: application comes from. Quote the header with double quotes, send the file with the binary data option, and prove the import with a GET of the active flows.

Two errors from one command line #

Both messages come from the one line you ran, one per request curl made:

  • curl: (6) Could not resolve host: application — after the real request, curl tried the leftover token as a second URL. No host named application exists, so the lookup fails with curl error 6. Command Prompt passed both single quotes through untouched.
  • {"code":"unexpected_error","message":"config.forEach is not a function"} — the request that did reach Node-RED carried the header as 'content-type:: an apostrophe in the header name and nothing after the colon. That is not the Content-Type name, so the request has no JSON content type, the body arrives as an unparsed string, and a string has no forEach method.
  • Decision: repair the quoting and resend the same file; leave the export and the instance alone.

How Command Prompt splits the line #

The line as typed:

curl -X POST http://localhost:1880/flows -H 'content-type: application/json' -d @flows

Command Prompt splits at spaces and hands curl eight arguments:

-X
POST
http://localhost:1880/flows
-H
'content-type:
application/json'
-d
@flows

-H takes the next token as its value, so the only header curl sends has an apostrophe in its name and an empty value. curl then finds a token that is not an option, application/json', treats it as a second URL, and fails resolving the host application. The JSON error is the response body of the first request; the resolve error belongs to the second. Two printed lines, one cause.

The corrected import #

curl -X POST http://localhost:1880/flows -H "Content-Type: application/json" --data-binary "@flows"
  • Double quotes make Command Prompt pass Content-Type: application/json as one argument, and the handler parses the body as JSON.
  • --data-binary reads the file and posts its bytes unchanged; the short -d form strips carriage returns and newlines from a file it reads, so the binary form is the right one in a deployment script.
  • The body must be a JSON array at the top level, which a normal export is. A small export with one tab and one inject node looks like this:
[{"id":"bed4fb91.f40858","type":"tab","label":"Sheet 1","disabled":false,"info":""},{"id":"3bcc44ce.14cafc","type":"inject","z":"bed4fb91.f40858","name":"Trigger","topic":"","payload":"","payloadType":"date","repeat":"3","crontab":"","once":false,"onceDelay":0.1,"x":340,"y":140,"wires":[[]]}]

The posted array becomes the entire active configuration: anything missing from the file is gone after the call. The optional Node-RED-Deployment-Type header selects how the change is applied, and with full every existing node is stopped before the new configuration starts — the behavior a first-time scripted install wants. On a live instance, save what is running before you replace it:

curl http://localhost:1880/flows > flows-backup.json

Success is an HTTP 200 whose JSON body carries the new configuration revision. If the body is still the unexpected_error object, the header did not arrive as JSON.

Keep the import on HTTP #

Switching the scheme to https produced a different failure: curl: (35) schannel: next InitializeSecurityContext failed: SEC_E_INVALID_TOKEN (0x80090308). Error 35 is a TLS handshake failure: on a default install the editor port speaks plain HTTP, so the handshake receives a non-TLS reply and aborts. Decision: for this script the import URL stays http on the local port.

The login check supports that. The GET of the login endpoint answered an empty JSON object and the POST still reached the flows handler, so this instance runs without adminAuth and the script sends no credentials. One rule goes with that: an unauthenticated admin API stays on localhost. Before the port is reachable from the plant network, enable adminAuth — the user setup behind it is what per-user login on a Node-RED dashboard really requires.

Verify the import #

Run these checks once by hand before the script does it unattended:

  1. Open the export and confirm the top level is an array: the first non-space character is an opening square bracket. A quoted string or a wrapped object is what the handler cannot iterate.
  2. Run the corrected POST. Neither printed error should appear; the body is the revision acknowledgment.
  3. Read the active configuration back with curl http://localhost:1880/flows and look for the ids from your file.
  4. Worked example: the export above holds two objects, one tab and one inject node wired to that tab, so after this replace the read-back holds exactly those two — the tab id bed4fb91.f40858 and the node whose z value points at it.
  5. Only then copy the line into the installer.

Scripting the deployment #

When the installer runs under Command Prompt or a batch file, use the double-quoted line exactly as above. Shell quoting differs per shell, so run the exact script line once in the shell that will execute it before the first unattended deployment. If the same deployment script installs Node-RED on Linux and stops at an apt repository error, the causes and the fix are in why the Node-RED install script fails at an apt repository error.

Questions asked

Why does the same single-quoted command work in a Bash script?

Bash and PowerShell both treat single quotes as string delimiters, so curl receives the header as one argument there; only Command Prompt passes the quotes through untouched. PowerShell has a trap of its own: the bare name curl can invoke the shell's built-in web-request command instead of the real tool, so there you call the executable by its full file name. Test the exact line in the shell that will run it.

What is the difference between POST /flows and POST /flow?

POST /flows replaces the entire active configuration with the array you send. POST /flow adds a single flow, shown as one tab in the editor, to the configuration already running, and it needs the flows.write permission once adminAuth is enabled. For a scripted first install of a complete export, use POST /flows; to add one tab to a live instance without touching the rest, use POST /flow.

Can the import run against a remote Node-RED instead of localhost?

Yes: put the target's address in place of localhost, for example 192.168.1.50, and once adminAuth is on, send a token with the call. That is also the moment authentication stops being optional: an unauthenticated admin API lets anything that can reach the port replace the flows, so a remote import is the point to enable adminAuth first.

Why did switching to https end in a schannel failure?

schannel is the Windows TLS provider in that curl build, and the code means the handshake received a reply that was not TLS, because the instance still speaks plain HTTP on that port. HTTPS works only after Node-RED is configured with a certificate in its settings file, and the import URL then changes scheme with it. For a local install script, plain HTTP on localhost is sufficient.

Keep reading

  • Troubleshooting

    Why a Node-RED Sparkplug B flow throws a touppercase type error

    A touppercase type error in a Sparkplug B publishing flow means a function block received a number, a float or an integer, where toUpperCase() needs a string. The nested PropertySet payload format is not the fault. Locate the function node that calls the method, convert that value or drop the conversion, then republish and check the payload separately.

    Edge computing and IIoT

  • Troubleshooting

    Fix Node-RED Docker x509 Certificate Expired on an Edge PC

    The error x509: certificate has expired or is not yet valid means Docker reached the registry over TLS but the controller clock falls outside the certificate's validity dates. Set the correct date and an NTP server, confirm the controller shows the right UTC time, and re-run the same docker run command — the pull verifies on the next connection. Change nothing else first.

    Edge computing and IIoT

  • Troubleshooting

    Fix Node-RED InfluxDB write errors after a network outage

    When InfluxDB output nodes throw ECONNRESET after a network outage, Node-RED is usually still holding dead TCP client sessions. Confirm the database is reachable from the Node-RED host, then use the Deploy menu's flow-restart option to rebuild every connection while the runtime stays up.

    Edge computing and IIoT

AVEVA Historian Flex licensing and redundancy credits explained