UNPKG

totalvirus-api

Version:

Node.js wrapper for VirusTotal API. Scan files, URLs, and fetch malware analysis reports.

45 lines (35 loc) 1.05 kB
const axios = require('axios'); const fs = require('fs'); const FormData = require('form-data'); const BASE_URL = 'https://www.virustotal.com/api/v3'; async function scanFile(apiKey, filePath) { const form = new FormData(); form.append('file', fs.createReadStream(filePath)); const response = await axios.post(`${BASE_URL}/files`, form, { headers: { 'x-apikey': apiKey, ...form.getHeaders() } }); return response.data; } async function scanUrl(apiKey, url) { const response = await axios.post(`${BASE_URL}/urls`, `url=${url}`, { headers: { 'x-apikey': apiKey, 'Content-Type': 'application/x-www-form-urlencoded' } }); return response.data; } async function getReport(apiKey, id) { const response = await axios.get(`${BASE_URL}/analyses/${id}`, { headers: { 'x-apikey': apiKey } }); return response.data; } module.exports = { scanFile, scanUrl, getReport };