Node: fs write() doesn't write inside loop. Why not?
I want to create a write stream and write to it as my data comes in. However, I am able to create the file but nothing is written to it. Eventually, the process runs out of memory. The problem, I've discovered is that I'm calling write() whilst inside a loop. Here's a simple example: 'use strict' var fs = require('fs'); var wstream = fs.createWriteStream('myOutput.txt'); for (var i = 0; i < 10000000000; i++) { wstream.write(i+'\n'); } console.log('End!') wstream.end(); Nothing ever gets written, not even hello. But why? How can I write to the file within a loop? To supplement @MikeC's