Deviopath › Node.js

Callback to Promise

Easy · Async

Older Node APIs like fs.readFile(name, callback) use error-first callbacks: the callback receives (err, data), and err is null on success. (In real code, util.promisify or fs.promises give you a Promise version.)

The starter has a fake readFileCallback(name, callback) that works the same way. Write an async function readConfig(name) that wraps it in a Promise and returns the file content, or the string "missing" if reading fails.

Next: Total File Size