I have a Node.js script that I have an array of objects which I do some processing on inside a forEach
loop, I want to have it so that when the forEach loop finishes that it then runs process.exit(0)
I'm not sure how to do this and googling these things together doesn't seem to yield much for helpful results.
I want something like
let array = [] // some data here
array.forEach((item) => {
console.log(item) // place holder
}
process.exit(0)
Now if I do this how it is the process will exit prematurely because of Node being async. I am trying to make it behave synchronously and was not sure how I could do that. I thought about a set timeout but that will not scale with what I need it to. I will never know how long it will take because the array will almost never be the same size.
How do I get it to exit the process when the forEach is complete?