title: How to close file descriptors in write streams
body: <p>I have the following code, which is a simplified example of what I am trying to do:</p>
  
  <pre><code>const fs = require('fs');
  
  var stream = fs.createWriteStream('/tmp/file');
  stream.once('open', function(fd) {
      for (var i = 0; i &lt; 100; i += 1) {
          stream.write('' + i + "\n");
      }
      stream.end();
      stream.close();
  });
  </code></pre>
  
  <p>I can see that <code>fd</code> is the file descriptor and I wanted to close it. I called <code>fd.close()</code>, but that is not a method.</p>
  
  <p>Two questions:</p>
  
  <ol>
  <li>Should I be closing it?</li>
  <li>How do I close it?</li>
  </ol>
  
  <p>I saw some documentation on <a href="https://nodejs.org/api/fs.html#fs_fs_close_fd_callback" rel="nofollow noreferrer"><code>fs.close()</code> and <code>fs.closeSync()</code></a>. Should I use that?</p>
  
  <p>Thanks.</p>