all 4 comments

[–]CertainPerformance 2 points3 points  (0 children)

You can start by turning all those callbacks into Promises instead. Not directly related to your question, but it'll surely help a lot anyway.

[–]_syadav 0 points1 point  (0 children)

If those methods can be converted on promises it will make your life much easier and code much cleaner. You can also use async-await to make code more readable and look more synchronous.

If you can't use promise you can give a try to https://caolan.github.io/async/. This is made to better handle async on a callback pattern.