I'm trying to create a batch of files with varying content and I'm running in to some strangeness. It may be my unfamiliarity with node streams but I'm wondering if you can help.
The actual content of the files doesn't seem to be written till the entire loop has finished, say I'm making 1000 files, it seems to create a thousand empty files then after that writes the data to them. This causes me to run in to a load of memory errors and everything falls over.
I think I'm missing something :)
Excerpt below, it's pretty basic stuff.
for (var j = nrOfFiles; j > 0; j--) {
fileName = 'randomFileNumber'+j;
filePath = 'tmp2/'+fileName+'.docx';
docx.setDocTitle(fileName);
pObj = docx.createP ();
pObj.addText("test");
out = fs.createWriteStream (filePath);
docx.generate (out);
}