Compressing files with node.js

Wed Jan 22 2014 15:26:25 GMT+0000 (Greenwich Mean Time)

I needed to compress entire folders with node.js and I tried several modules until I found one that worked. The one that actually worked for me was archiver, which apparently can do TAR apart from ZIP.

To install using npm just do

npm install archiver

It's good that you can specify if you want relative paths and all those niceties. Also, it uses streams, which I'm still learning to use, but they're better than reading the whole thing in memory.

Here's how you'd use it to add everything in srcDirectory recursively: