What are ES6 generators and how can I use them in node.js?

I was at a node.js meetup today, and someone I met there said that node.js has es6 generators. He said that this is a huge improvement over callback style programming, and would change the node landscape. Iirc, he said something about call stack and exceptions.

I looked them up, but haven’t really found any resource that explains them in a beginner-friendly way. What’s a high-level overview of generators, and how are the different (or better?) than callbacks?

PS: It’d be really helpful if you could give a snippet of code to highlight the difference in common scenarios (making an http request or a db call).

9 thoughts on “What are ES6 generators and how can I use them in node.js?”

Leave a Comment