'use strict'
const Fs = require('fs')
const Path = require('path')
const Axios = require('axios')
async function downloadImage () {
const url = 'https://unsplash.com/photos/AaEQmoufHLk/download?force=true'
const path = Path.resolve(__dirname, 'images', 'code.jpg')
const writer = Fs.createWriteStream(path)
const response = await Axios({
url,
method: 'GET',
responseType: 'stream'
})
response.data.pipe(writer)
return new Promise((resolve, reject) => {
writer.on('finish', resolve)
writer.on('error', reject)
})
}
downloadImage()
Last active
April 5, 2019 13:27
-
-
Save hungdev/ea8f963dd1818a30164052c72e5016c0 to your computer and use it in GitHub Desktop.
node download
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment