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.
