Created
December 6, 2019 16:52
-
-
Save viniciusgati/73f80de6f6c77fd457e278d1e30db6aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| '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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment