Skip to content

Instantly share code, notes, and snippets.

@lamthuyvo
Created December 6, 2016 20:23
Show Gist options
  • Select an option

  • Save lamthuyvo/d7cae77f9b4aa01d79e8b92e117732cb to your computer and use it in GitHub Desktop.

Select an option

Save lamthuyvo/d7cae77f9b4aa01d79e8b92e117732cb to your computer and use it in GitHub Desktop.

Revisions

  1. lamthuyvo created this gist Dec 6, 2016.
    33 changes: 33 additions & 0 deletions url-expander.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    // 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');
    }