P
P
ptvalx2020-06-20 00:15:48
Node.js
ptvalx, 2020-06-20 00:15:48

How to handle the Successful save event in fs.promises.writeFile?

I want to asynchronously write data to a file and when the file is written, handle this event.
I looked at the documentation ( https://nodejs.org/api/fs.html#fs_fs_writefile_fil...

FSP.writeFile(dir_task + '/mapdata.json', JSON.stringify(mapdata), 'utf8', (err) => {
    Log('1234');
    if (err) throw err;
    Log('1234676');
    task.stat.is_end = true;
});


The file is saved, but the function is not executed. I tried to cause an error by specifying a crooked path - an exception fell out, but the handler also did not get called.
I tried to write {encoding: 'utf8'} instead of 'utf8'. I tried instead of (err) => write function(err)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2020-06-20
@ptvalx

Promises do not have a callback, but the then
FSP.writeFile(....).then(okHandler, errorHandler);
https://learn.javascript.ru/promise-basics

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question