I would like to use node to download the .txt file from this link:
https://raw.githubusercontent.com/monosans/proxy-list/main/proxies/http.txt
and save it into the same directory as my .js file.
After doing some research it seems most answers here on stack overflow use the request method which is now deprecated.
What is the best way to do this without using 3rd party libraries?
>Solution :
You can use https module:
const https = require('https');
const fs = require('fs');
const url = 'https://raw.githubusercontent.com/monosans/proxy-list/main/proxies/http.txt';
https.get(url, (response) => {
const file = fs.createWriteStream('http.txt');
response.on('data', (chunk) => {
file.write(chunk);
});
response.on('end', () => {
console.log('File downloaded successfully');
file.end();
});
}).on('error', (err) => {
console.error('Error: ', err.message);
});