Categories
JavaScript Answers

How to fix this error TypeError [ERR_INVALID_CALLBACK]: Callback must be a function with Node?

Spread the love

To fix this error TypeError [ERR_INVALID_CALLBACK]: Callback must be a function with Node, we pass in a function as the callback.

For instance, we write

const fs = require("fs");

fs.readFile("readMe.txt", "utf8", (err, data) => {
  fs.writeFile("writeMe.txt", data, (err, result) => {
    if (err) console.log("error", err);
  });
});

to call readFile with the callback as the 3rd argument.

And we call writeFile with the callback as the 3rd argument.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *