(...) // open var stream = fs.createWriteStream('filename'); // stream data stream.write(data); // close stream.close();