Node.js · Junior · Question 32 of 75
What is an 'error-first callback'?
fs.readFile("data.txt", "utf8", (err, data) => {
// ...
});- 1A callback that must throw an error to stop the program
- 2A callback that runs only when an error happens
- ✓Correct answer: A Node.js convention: the first argument of a callback is an error (or
null), the next ones are the results
Explanation
Always check err first. Classic Node.js APIs follow this pattern; most also have promise versions, such as fs/promises.