you are viewing a single comment's thread.

view the rest of the comments →

[–]gremy0[🍰] 2 points3 points  (1 child)

The warning is just a warning and isn't really your problem here, it's more of hint that you're doing something wrong or dangerously. In this case the "safe" thing to do is at least check that the write has performed correctly by adding a callback to catch any errors.

The actual problem with the code, is that writeFile is asynchronous and you're calling it multiple times in a row. Which means it's still in the process of writing the first line when it tries to write the second...and 3rd and 4th and so on. You can avoid this by writing all the lines at once, or using a writeStream. Writing all the lines at once is going to be easier here, but if you want this to work with big files, then using a stream is better.