Workflow Not Waiting for Previous Node to Finish Before Executing Next

Hi everyone, I’m facing an issue where my n8n workflow seems to run nodes out of order. I have a flow where one node depends on the result of the previous one, but sometimes it looks like the next node executes before the previous node fully completes.
My workflow looks like this:
Webhook → HTTP Request → Function → Database
In the HTTP Request node, I fetch data from an API, then process it in a Function node, and finally insert it into the database
const data = $json.data;
return data.map(item => ({
json: {
id: item.id,
name: item.name
}
}));

Sometimes, I notice that:
• The Function node runs with empty or incomplete data
• The Database node inserts partial records
• It feels like the HTTP Request hasn’t fully finished before the next node runs

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @Roseline

n8n actually does run nodes sequentially, so the next node will not execute until the previous one finishes. So this isn’t really an out of order issue.

What’s likely happening is that your HTTP Request node is not returning the data in the structure you expect, so by the time it reaches the Function node, $json.data is sometimes undefined or empty.

For example, if the API response is not wrapped in data, this line will break:const data = $json.data;

If data is undefined, your Function node ends up working with empty input.

A safer approach is to log and validate the input before processing:const data = $json.data || ;

return data.map(item => ({
json: {
id: item.id,
name: item.name
}
}));

Also double check:
• The HTTP Request response format (is it really { data: […] }?)
• If you enabled “Split Into Items” in the HTTP node (this changes the structure)
• Whether the API sometimes returns empty responses or errors

So the issue isn’t timing its data structure inconsistency between nodes.

2 Likes

niffzy nailed it — that data structure mismatch is super common, especially when youre chaining different api responses. weve been caught by this exact thing before when migrating workflows between environments. try logging the raw output from the http node to see what shape youre actually getting back, that usually clears it up real fast

1 Like

Thanks so much @Niffzy

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