I'm trying my first steps with Node-RED.
I would like to use the split and join nodes in an HTTP flow, but the res
property gets lost on join, so my flow fails with the HTTP response node complaining about "no response object".
A simplified example, consisting of four nodes (HTTP In, Split, Join, HTTP Response), using the "reduce sequence" example from the documentation to calculate the average of an array of numbers:
[
{
"id": "9e5f48c16729e4f0",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": "",
"env": []
},
{
"id": "f4209033d0b98ad1",
"type": "join",
"z": "9e5f48c16729e4f0",
"name": "",
"mode": "reduce",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": true,
"timeout": "",
"count": "",
"reduceRight": false,
"reduceExp": "$A+payload",
"reduceInit": "0",
"reduceInitType": "num",
"reduceFixup": "$A/$N",
"x": 530,
"y": 200,
"wires": [
[
"40982d7b37a20db2"
]
]
},
{
"id": "40982d7b37a20db2",
"type": "http response",
"z": "9e5f48c16729e4f0",
"name": "",
"statusCode": "",
"headers": {},
"x": 750,
"y": 200,
"wires": []
},
{
"id": "d7649e2faf944cea",
"type": "split",
"z": "9e5f48c16729e4f0",
"name": "",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "",
"x": 330,
"y": 200,
"wires": [
[
"f4209033d0b98ad1"
]
]
},
{
"id": "de29676d03629e55",
"type": "http in",
"z": "9e5f48c16729e4f0",
"name": "",
"url": "/avg",
"method": "post",
"upload": false,
"swaggerDoc": "",
"x": 120,
"y": 200,
"wires": [
[
"d7649e2faf944cea"
]
]
}
]
When invoking this with
curl -d "[2,3,4]" -H "Content-Type: application/json" "http://localhost:1880/avg"
I would expect to get "3" as response. Instead, the flow fails with "no response object".
I can see that the messages sent by the split node still contain the req
and res
properties, while the join node sends a message with only the payload and no req
or res
properties, which in my understanding is causing the problem.
What am I doing wrong?