Skip to content

Instantly share code, notes, and snippets.

Created December 6, 2016 20:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lamthuyvo/d7cae77f9b4aa01d79e8b92e117732cb to your computer and use it in GitHub Desktop.
// 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 = [ "", ""
var counter=0;
var q = async.queue(function (shortUrl, callback) {
// expander function
urlExpander.expand(shortUrl, function(err, longUrl){
// log the short url and the expanded url in the console
console.log(shortUrl + "," + longUrl);
}, 100);
// runs the expander function for each data point
var i = 0;
while (i< data.length){
q.push(data[i], function (err) {
// tells you in your console when you're done
q.drain = function() {
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