Skip to content

Instantly share code, notes, and snippets.

@tanvirstreame
Created January 23, 2022 06:48
Show Gist options
  • Select an option

  • Save tanvirstreame/6cd1801607065a59966bf2f7df0848dd to your computer and use it in GitHub Desktop.

Select an option

Save tanvirstreame/6cd1801607065a59966bf2f7df0848dd to your computer and use it in GitHub Desktop.
const fs = require('fs')
const request = require('request')
const download = (url, path, callback) => {
request.head(url, (err, res, body) => {
request(url)
.pipe(fs.createWriteStream(path))
.on('close', callback)
})
}
const url = 'https://…'
const path = './image.png'
download(url, path, () => {
console.log('✅ Done!')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment