What is the Best Way to Make a Post Request with a 5 Second Wait Between Each Value in Node.js?

This topic was automatically generated from Slack. You can find the original thread here.

Hi everyone,
How can I create a Node.js step that makes a post request to an array but with 5 second wait between each value in an array?

The reason is not to get error for rate limitation on the 3rd party API.

Basically for each item in the array sends the request and wait a few seconds before proceeding to the next one?

Exactly

I know how to build it but I don’t know how to put the delay between each item in the array

There’s a very simple await delay() I’ve used in the past, I’ll send it soon (you can also ask chat GPT I’m sure they’ll give a working example)

I’ve used this before

const delay = (ms) => new Promise((res) => setTimeout(res, ms));
await delay(5000); // 5s

I appreciate it.
I just tried and it works like a magic

check out the code formatting in Discourse - it includes the HTML tags (making the code unusable)

Good catch! Will fix