title: Need to ZIP an entire directory using Node.js
body: <p>I need to zip an entire directory using Node.js. I'm currently using node-zip and each time the process runs it generates an invalid ZIP file (as you can see from <a href="https://github.com/Stuk/jszip/issues/41" rel="noreferrer">this Github issue</a>).</p>
  
  <p>Is there another, better, Node.js option that will allow me to ZIP up a directory?</p>
  
  <p>EDIT: I ended up using <a href="https://npmjs.org/package/archiver" rel="noreferrer">archiver</a></p>
  
  <pre><code>writeZip = function(dir,name) {
  var zip = new JSZip(),
      code = zip.folder(dir),
      output = zip.generate(),
      filename = ['jsd-',name,'.zip'].join('');
  
  fs.writeFileSync(baseDir + filename, output);
  console.log('creating ' + filename);
  };
  </code></pre>
  
  <p>sample value for parameters:</p>
  
  <pre><code>dir = /tmp/jsd-&lt;randomstring&gt;/
  name = &lt;randomstring&gt;
  </code></pre>
  
  <p><strong>UPDATE:</strong> For those asking about the implementation I used, <a href="https://github.com/commadelimited/JSDownloader/blob/master/routes/download.js" rel="noreferrer">here's a link to my downloader</a>:</p>