Home > database >  TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. in my node express app
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. in my node express app

Time:09-28

Received undefined throw new ERR_INVALID_CALLBACK(cb); In my node-express app i'm stuck here solutions are most welcom

const fs = require("fs");
const text = "File ";

fs.writeFile("node-message.txt", text)
  .then(() => {
    console.log("File Created");
  })

  .catch(() => {
    console.log("File not created");
  });

CodePudding user response:

You have to just require your module with promises as mentioned below code...

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");
  });
  • Related