Delivery Notes - ga-wdi-boston/node-api-promises GitHub Wiki
Framing
You need to able to read documentation that uses callback signatures even when promises are available. Looking ahead to: Mongoose documentation doesn't use promises, but we use the promisified versions
Working in legacy code or without the tooling that GA provides, you may have to learn how do this. Emphasize that what we want to learn is the pattern of how to promisify things.
General Notes
Have promise MDN docs open
Node does not promisify things,
Create promisifying template on the board:
new Promise((resolve, reject) => {
if (error) {
reject(error);
}
resolve(true);
});
});
Steps:
- Use the method that takes the callback.
- Create a similarly named wrapper function.
- Use the function's signature to determine how promisifying works:
fs.writeFile(path, data, options, callback)
=>promisifiedWriteFile(path, content, options).then(cb)
The original callback argument was a specific siganture, so that signature is used in the promise definition as the executor function.