How to virus scan a RAR archive in Node.JS

Virus scanning is a crucial feature, but you probably don’t want to break the bank or waste an entire day coding it. We have a lovely compromise for you: one of our handy APIs.

First task, add this reference to your package.json file, so that our API client can be installed.

"dependencies": {
"cloudmersive-virus-api-client": "^1.1.3"

With that complete, all that we have left to do is call our scanFile function, shown below.

var CloudmersiveVirusApiClient = require('cloudmersive-virus-api-client');var defaultClient = CloudmersiveVirusApiClient.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 CloudmersiveVirusApiClient.ScanApi();var inputFile = "/path/to/file"; // File | Input file to perform the operation on.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.scanFile(inputFile, callback);

Go ahead and test it out on your RAR file, and you will be alerted of any potential viruses or malware from a library of over 17 million definitions.

Image for post

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