const fs = require('fs');
const { resolve } = require('path');
const { promisify } = require('util');
const writeFile = promisify(fs.writeFile);
const got = require('got');
async function getImage(url)
{
try
{
const { body, statusCode, statusMessage } = await got(url, { encoding: null });
if (statusCode === 200)
{
await writeFile(resolve('.', 'newCaptchaAnchor.gif'), body);
}
else
{
throw new Error(statusMessage);
}
}
catch(err)
{
throw new Error(err);
}
}
getImage('https://developers.google.com/recaptcha/images/newCaptchaAnchor.gif')
.then(() => console.log('Complete....'));