Reputation: 7580
I know that foreach in nodejs is blocking. I am developing a API Server in nodejs and I need to parse through req.body to produce some kind of signature to validate request. So my question is if I use forEach on req.body will it block other request? How to overcome it if it is blocking?
Upvotes: 0
Views: 990
Reputation: 1
i find async perfect for server-side short work - but if you want something much lighter and can deal with less polish you can adapt one of these: http://book.mixu.net/ch7.html
a lot faster from my experience...which is important when running on low-power embedded devices or low-end servers
Upvotes: 0
Reputation: 17319
forEach is blocking, but for most use cases it's just fine, so long as your array.length * function.runTime isn't very large, which it shouldn't be unless you're doing IO or crypto. If you are doing something with a long run time you can then replace the forEach with an async.forEach (https://github.com/caolan/async)
Upvotes: 2