Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const axios = require('axios')
- /**
- * Download url to a file on disk
- * @param url
- * @param destFile
- */
- async function downloadAxios(url: string, destFile: string) {
- const response = await axios({
- method: 'GET',
- url: url,
- responseType: 'stream' // axios image download
- })
- response.data.pipe(fs.createWriteStream(destFile)) // pipe the result stream directly to a file
- // return a promise
- return new Promise((resolve, reject) => {
- response.data.on('end', () => {
- resolve()
- })
- response.data.on('error', () => {
- reject()
- })
- })
- }
Add Comment
Please, Sign In to add comment