ENOENT using fs.appendFile ()

I am trying to add data to some files.

The docs say fs.appendFile:

Asynchronously add data to the file, creating the file; if it does not already exist, the data can be a string or a buffer

function appendData(products) {
var productsPromises = products.map(function(product) {
    var title = product['title'];
    return fs.appendFile('/XXXXX/' + title, product, 'utf8', function(err){
        console.log(err);
    });
});
return Promise.all(productsPromises);
}

I get an error message:

ENOENT, open '/ XXXXX / PPPPPPPPP'

What am I doing wrong?

+4
source share
2 answers

You may have accidentally added /before XXXXX.

I expect it to write to the folder XXXXXthat is in the same place where you started the application, and then change your code to:

return fs.appendFile('XXXXX/' + title, product, 'utf8', function(err){

As / , . XXXXX, @Rahil Wazir.

+6

, .

:

return fs.appendFile('./XXXXX/' + title, product, 'utf8', function(err){
+2

All Articles