How do I unzip a .zip/.rar file in Node.js into a folder

node.js

Solution

There are plenty of node modules that can do this for you. One of them is node-unzip. You can extract a .zip file to a directory as simple as this.

`fs.createReadStream('path/to/archive.zip').pipe(unzip.Extract({ path: 'output/path' }));`

Further reading: https://github.com/EvanOxfeld/node-unzip

Problem

I am using zlib along with fstream now for zipping and sending to the client, Now I need to unzip an archive(which may contains sub folders) into a folder maintaining the folder structure. How do I do that?

Original source