Callback ➡ Promise
Promise ➡ Callback
Bonus: NodeJS util.promisify and util.callbackify
When converting between callback style and promises, NodeJS has a handy pair of tools specifically made for this purpose. The one thing to note is that the callback function signature is
- util.promisify: https://nodejs.org/api/util.html#util_util_promisify_original
- util.callbackify: https://nodejs.org/api/util.html#util_util_callbackify_original
Which one is best?
Whichever makes your code more intelligible.
Each is a separate way of organizing the paths that your code takes. Callbacks are slightly faster and with less overhead, but the performance difference is negligible compared to the gains in readability of your code. Naturally, performance may be important in highly repetitive tasks, but coincidentally, these tasks tend to be more readable when written in the callback form.