DEV Community

Dharmender Kumar
Dharmender Kumar

Posted on

No More Sneaky Uploads : How I Made My Node.js App Virus-Free🛡️🦠

So, I’m working on An app, and today it hit me like: What if someone tries to sneak in a virus through a file upload?

Image description

But then I found this awesome tool called ClamAV, and its command-line sidekick clamscan, which is like a hero for keeping your app safe from malicious files. Also it's super-easy to integrate in Node.js project.

What I Figured Out

ClamAV is a free, open-source antivirus engine that scans files for viruses, trojans, and other nasty stuff. Think of it as the bouncer at your app’s file upload gate, checking IDs and kicking out troublemakers.(same like security guard of your college😁)

😎Quick Setup Guide-

1). npm i clamscan

2). How to use it in your code-

const NodeClam = require('clamscan');

(async () => {
  const clamscan = await new NodeClam().init();
  const { isInfected, viruses } = await clamscan.isInfected('/path/to/your/file');

  if (isInfected) {
    console.log(`🚨 Uh-oh, infected file! Found: ${viruses}`);
    // Toss the file or block the upload
  } else {
    console.log('🎉 File’s all good!');
  }
})();
Enter fullscreen mode Exit fullscreen mode

that's it . this simple code block can prevent malicious files from being uploaded by users in database

Image description

Hope this helps you,
Let’s build safe and secure apps.

-Dharm

Top comments (0)