Node.js · Junior · Question 32 of 75

What is an 'error-first callback'?

fs.readFile("data.txt", "utf8", (err, data) => {
  // ...
});

Explanation

Always check err first. Classic Node.js APIs follow this pattern; most also have promise versions, such as fs/promises.

Further reading

Problem with a question

Node.js · Junior · question 32

Test yourself

Take the Node.js · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz