title: Node.js - Cannot delete file created with createWriteStream and written to
body: <p>I cannot find any solution for this problem. Using Node fs I create a file with createWriteStream, write data to it and then try to delete it but it cannot be deleted while node is open.</p>
  
  <p>The following is the code I am using for this process:</p>
  
  <pre><code>var file = fs.createWriteStream("test.txt", {flags: "a");
  file.write(new Buffer(1048576));
  </code></pre>
  
  <p>The file is created with success and the 1MB of empty data is written to it correctly. The problem is when I try to <code>fs.unlink</code> the file or delete it manually (Windows - Delete file), it disappears from the folder but once I refresh the folder the file is still there, it is always there until Node is closed. I think it gets marked for deletion once it is no longer in use by Node.</p>
  
  <p>I've tried closing the file after the process with <code>file.close()</code>, <code>file.end()</code>, <code>file.emit("close")</code>, <code>file.emit("end")</code> and a few others but still could not delete the file.</p>
  
  <p>How can I "finish" the file so that it can be deleted when I need to? I thought it closed itself after being written to.</p>