Generate a password protected ZIP file in node.js

If you work on linux then you can do it with the help of zip (command line utility in most linux distributions). Just include the following in you app.

spawn = require('child_process').spawn;
zip = spawn('zip',['-P', 'password' , 'archive.zip', 'complete path to archive file']);
zip .on('exit', function(code) {
...// Do something with zipfile archive.zip
...// which will be in same location as file/folder given
});

If you want to zip a folder just put another argument '-r', before the folder path instead of file path.

Remember this spawns separate thread, from main process, so it is non blocking. For more info on child_process look here http://nodejs.org/api/child_process.html


For anyone who ends up here like I did, I tried several packages in node but ended up using this one: https://www.npmjs.com/package/minizip-asm.js

It supports passwords (using AES) and is really easy to use. I'm surprised it doesn't have that many downloads given that it's the only one I found supporting passwords.


I had the same issue and couldn't find the package to do it, so I've written one on my own, as a plugin to archiver package. Pure JS, no external zip software needed.

Here it is - https://www.npmjs.com/package/archiver-zip-encrypted. Supports both legacy Zip 2.0 encryption and AES-256 encryption from WinZip.