Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser. To scan for malware in file using Javascript, we offer three sample code snippets using different method. Alternatives includes using the code snippets below using Axios
, Native
, Request
, and Unirest
.
For the Javascript tutorial, please check out this link.
REPLACE_ME
with your API key.location
value in payload with url location of your file.callback
value in payload to your webhook url. We recommend using webhook.site as a callback url during test.For 2 and 3, you can find this documented at Offical Documentation
const axios = require('axios');
let data = JSON.stringify({
"location": "https://filescanapi.com/icon.png",
"metadata": {
"filename": "demo.png"
},
"callback": "https://webhook.site"
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.filescanapi.com/v1/file/async',
headers: {
'x-api-key': 'REPLACE_ME',
'Content-Type': 'application/json'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
var https = require('follow-redirects').https;
var fs = require('fs');
var options = {
'method': 'POST',
'hostname': 'api.filescanapi.com',
'path': '/v1/file/async',
'headers': {
'x-api-key': 'REPLACE_ME',
'Content-Type': 'application/json'
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
var postData = JSON.stringify({
"location": "https://filescanapi.com/icon.png",
"metadata": {
"filename": "demo.png"
},
"callback": "https://webhook.site"
});
req.write(postData);
req.end();
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://api.filescanapi.com/v1/file/async',
'headers': {
'x-api-key': 'REPLACE_ME',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"location": "https://filescanapi.com/icon.png",
"metadata": {
"filename": "demo.png"
},
"callback": "https://webhook.site"
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
var unirest = require('unirest');
var req = unirest('POST', 'https://api.filescanapi.com/v1/file/async')
.headers({
'x-api-key': 'REPLACE_ME',
'Content-Type': 'application/json'
})
.send(JSON.stringify({
"location": "https://filescanapi.com/icon.png",
"metadata": {
"filename": "demo.png"
},
"callback": "https://webhook.site"
}))
.end(function (res) {
if (res.error) throw new Error(res.error);
console.log(res.raw_body);
});