#node.js #express #fs
Вопрос:
Получен неопределенный бросок новый 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");
});
Я получаю эту [ERR_INVALID_CALLBACK]
ошибку типа : обратный вызов должен быть функцией.
Ответ №1:
Вам необходимо запросить fs module
с обещаниями, если вы столкнулись с ошибкой недопустимого типа обратного вызова.
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");
});