
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
antivirus-microservice
Advanced tools

This is a free antivirus microservice for file scanning using ClamAV. The service is written in TypeScript and uses Bun as the runtime environment.
Demo with default maximum file upload size 512Kb is here
Free solution for antivirus file scanningClamAV antivirus engineDockerRESTful API for file upload and scanningClamAV to start upClone the repository:
git clone https://github.com/ivanoff/antivirus-microservice.git
cd antivirus-microservice
Build the Docker image:
sudo docker compose build
Start the service:
sudo docker compose up
After successful startup, you will see the message:
[2024-08-10T11:27:05.038Z] Service started on 3000 port
The service provides a single endpoint for uploading and scanning files.
Send a POST request to http://localhost:3000 with the file in a multipart/form-data form.
Example of checking a file without a virus:
curl -X POST http://localhost:3000 -F "file=@Dockerfile"
Response:
{"ok":true}
To demonstrate working with an infected file, first create a test virus:
base64 -d virus.txt.base64 > virus.txt
Then send the file for scanning:
curl -X POST http://localhost:3000 -F "file=@virus.txt"
Response:
{"ok":false,"viruses":["Eicar-Signature"]}
This client provides a simple interface to interact with the Antivirus Microservice. It allows you to easily scan files for viruses using the ClamAV engine.
See Antivirus Microservice Server section to set up the server.
To install the Antivirus Microservice client, use npm:
npm i -S antivirus-microservice
Here's a basic example of how to use the Antivirus Microservice client:
import Antivirus from 'antivirus-microservice';
// Initialize the client with the server URL
const antivirus = new Antivirus('http://localhost:3000');
// For example: Create a test file (this is the EICAR test virus file)
const file = new File(['X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*'], 'test.txt', { type: 'text/plain' });
// Check the file
const { ok, viruses } = await antivirus.checkFile(file);
// Log the result
console.log(ok? 'File is clean' : `File is infected: ${viruses}`);
// Result> File is infected: Win.Test.EICAR_HDB-1
In this example, we're creating a file with the EICAR test virus signature. This is a standard test file used to verify that antivirus software is working correctly. When scanned, it should be detected as a virus.
The Antivirus class provides the following method:
checkFile(file: File | Blob): Promise<{ ok: boolean, viruses?: string[], error?: string }>
Scans the provided file for viruses. Returns a promise that resolves to an object with:
ok: boolean indicating whether the file is clean (true) or infected (false)viruses: an array of detected virus names (only present if ok is false)error: a string with error (only present if ok is false)Antivirus client.File and Blob objects, making it flexible for various use cases.checkFile method will return { ok: false, viruses: ['Error checking file'] }.For more information on setting up and using the server, refer to the Antivirus Microservice Server documentation above.
Here is the Nginx configuration with a 200MB file size limit set as an example:
server {
listen 80;
server_name antivirus.your-domain.com;
root /path/to/antivirus-microservice/www;
index index.html;
error_log /var/log/nginx/antivirus.your-domain.com.error.log;
access_log /var/log/nginx/antivirus.your-domain.com.access.log;
location / {
}
location /check {
rewrite ^/check /$1 break;
resolver 127.0.0.1;
proxy_pass http://antivirus-server:3000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_connect_timeout 120;
proxy_send_timeout 120;
proxy_read_timeout 180;
client_max_body_size 100M;
}
}
This project is distributed under the MIT license. See the LICENSE file for more information.
Please note that ClamAV is licensed under the Apache 2.0 license. More details can be found here
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
If you encounter any problems or have questions, please open an issue in the project repository.
Dimitry Ivanov 2@ivanoff.org.ua # curl -A cv ivanoff.org.ua
FAQs
Antivirus Microsevice
The npm package antivirus-microservice receives a total of 1 weekly downloads. As such, antivirus-microservice popularity was classified as not popular.
We found that antivirus-microservice demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.