3

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

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

1 Answer 1

3

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");
  });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.