Lesson 23 — Promisify a callback
Wrap old callback APIs
Older code reports results through a callback — a function you pass in, called as cb(error, value) when the work finishes (error-first style). Promisifying wraps such a function so it returns a Promise instead: reject when there is an error, resolve with the value otherwise. Node even ships util.promisify for this.
function readLater(cb) { setTimeout(() => cb(null, "data"), 10); }
// promisified: readLaterP().then(console.log)
Why it matters: it lets you use await with legacy libraries instead of nesting callbacks.
Finish promisify so the failing call prints error: boom and the working call prints 42.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based JavaScript Intermediate courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for JavaScript Intermediate books — check the publication year so the examples match current versions.
Search Amazon →