How to compress files to create a new zip archive in Node.JS

Today’s lesson shows how to create zip archives using Node.JS in record time. Let’s dive straight in.

We shall use npm install to set up our client:

npm install cloudmersive-convert-api-client --save

Our function can then be implemented like this:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.ZipArchiveApi();var request = new CloudmersiveConvertApiClient.CreateZipArchiveRequest(); // CreateZipArchiveRequest | Input requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.zipArchiveZipCreateAdvanced(request, callback);

And that’s really all there is to that. Simple, right?

Cloudmersive has a ton more APIs like this, ready to simplify your project, and they all have similar implementation. With their help, you can do anything from converting files between formats to facial recognition, all in a matter of mere minutes.

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store