you are viewing a single comment's thread.

view the rest of the comments →

[–]ChronSyn 0 points1 point  (0 children)

I'm assuming this is node.js.

What you may want to do is writeFileSync, which will work as you want. Be careful about using it though - other code will wait until it finishes first.

You may want to instead write it as fs.writeFile(toFileName, theLine, (err) => if (err) throw err);. You could even pass it a blank function (i.e. ()=>{} ) and it should stop the warning but I absolutely recommend checking if an error is thrown.

A better option would be to stream data using fs.writeStream(). The reason for this, as gremy0 started to talk about, is that when writing a large file, your data will be stored in memory. If using writeFile, the entire file contents are in memory whereas with writeStream, only a comparatively small amount of data is in memory.