import * as https from 'https'; import * as fs from 'fs'; async function downloadSong(downloadLink: string, folder: string, filename: string, songCount: number): Promise { console.log(`Downloading song #${songCount} ...`) return new Promise((resolve, reject) => { https.get(downloadLink, (response) => { response.pipe(fs.createWriteStream(`${folder}/${filename}.mp3`)) .on('finish', () => { console.log(`${songCount} songs downloaded successfully`); resolve(); }) .on('error', (error: Error) => { console.error('Error downloading song:', error); reject(error); }); }); }); } process.on('message', async (message: any) => { const { downloadLink, folder, filename, songCount } = message; await downloadSong(downloadLink, folder, filename, songCount); process.send && process.send(`Song #${songCount} downloaded successfully`); });