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.
We'll cover the following...
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 archiverin the terminal. This command will install the dependency intonode_modulesand add it to the project’s dependencies in itspackage.jsonfile. However, you will not have to do this right now, as these dependencies have already been listed in the current project’spackage.jsonfile.
As a reminder,npm installlooks at your project’spackage.jsonfile and installs all of the ...