Search⌘ K

Zipping Files

Discover how to automate zipping files in Node.js by using the Archiver package along with native modules like fs and path. Learn to write scripts that compress multiple files into a zip archive, handle streams efficiently, and manage errors. This lesson helps you create automation tools to reduce file sizes for easier transfer and improve productivity.

Installing dependencies

Up until now, you have been making use of Node’s standard API library, such as the process, path, and os modules. If you want to extend your choice to use more libraries that provide further functionality, you can turn to npm. The npm ecosystem is huge and if you search for a library with certain functionality, chances are that you will find it.

Suppose a member of your team has requested that you zip up a text file and an image. To accomplish this, you will use an external dependency identified as: archiver.

Note: As you might recall from the previous lessons, for installing a dependency, you would normally need to run the npm install archiver in the terminal. This command will install the dependency into node_modules and add it to the project’s dependencies in its package.json file. However, you will not have to do this right now, as these dependencies have already been listed in the current project’s package.json file.

As a reminder, npm install looks at your project’s package.json file and installs all of the ...