Received undefined throw new ERR_INVALID_CALLBACK(cb);
const fs = require("fs");
const text = "File ";
fs.writeFile("node-message.txt", text)
.then(() => {
console.log("File Created");
})
.catch(() => {
console.log("File not created");
});
Iam getting this TypeError [ERR_INVALID_CALLBACK]: Callback must be a function.
CodePudding user response:
You have to require an fs module
with promises if you are facing an invalid callback type error.
const fs = require("fs").promises;
const text = "File ";
fs.writeFile("node-message.txt", text)
.then(() => {
console.log("File Created");
})
.catch(() => {
console.log("File not created");
});