Created
December 6, 2016 20:23
-
-
Save lamthuyvo/d7cae77f9b4aa01d79e8b92e117732cb to your computer and use it in GitHub Desktop.
This file contains 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
// load all dependencies | |
var request = require('request'); | |
var async = require('async'); | |
var urlExpander = require('expand-url'); | |
// add your own array of links here | |
var data = [ "http://bzfd.it/2g6Kraz", "http://bzfd.it/2ghsm88" | |
] | |
var counter=0; | |
var q = async.queue(function (shortUrl, callback) { | |
// expander function | |
urlExpander.expand(shortUrl, function(err, longUrl){ | |
counter++; | |
// log the short url and the expanded url in the console | |
console.log(shortUrl + "," + longUrl); | |
callback(); | |
}); | |
}, 100); | |
// runs the expander function for each data point | |
var i = 0; | |
while (i< data.length){ | |
q.push(data[i], function (err) { | |
}); | |
i++; | |
} | |
// tells you in your console when you're done | |
q.drain = function() { | |
console.log(counter); | |
console.log('all urls have been processed'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment