I'm trying to download an image and then upload the image to Twitter. When I try to download the image it won't download until the app has finished which means I can't upload it to Twitter.
I believe the node.js is asynchronous so this is causing the issue. Any suggestions would be great.
Below is my download function.
// downloads the image
function download(url){
var request = require('request'),
fs = require('fs'),
url = url;
count = count + 1;
request(url, {encoding: 'binary'}, function(error, response, body) {
fs.writeFile('downloaded'+ count + '.jpg', body, 'binary', function (err) {
});
});
}
I've tried using writeFileSync but that doesn't seem to work.