Node.js It's Not Just for Websites

Back to Listing

Node.js It's Not Just for Websites


18 Jun, 2012


So I have been working on a node.js project recently, that I was hosting on Heroku. Sadly, Heroku doesn't allow socket.io based node apps to use true websockets. So I asked my good friend Adron who was the best Heroku-like node host out there that did support it. He suggested Nodejitsu.

So I signed up and my hopes were immediately dashed when I discovered they are metering access to their beta. You have to camp out on their activation site waiting for them to allot a few more activations. This sounded boring. So I decided to automate it with node of course. I fired up Sublime Text 2 and ripped this out.

var util = require('util'),  
    exec = require('child_process').exec,
    rest = require('restler');

var alertMe = function(){  
    exec('say -v Cellos Bobby, come get your nodejitsu beta');
};

var checkSite = function(){  
    util.puts('checking if I can get you into the beta yet.');
    rest.get('http://activate.nodejitsu.com/').on('complete', function(result){
        if(result instanceof Error) {
            util.puts('Error: ' + result.message);
        } else {
            if(result.indexOf('We\'ve hit our limit today. Please try again later.') < 0)
                alertMe();
            else
                util.puts('damn it...');
       }
    });
};

var pollingSite = setInterval(checkSite, 10000);  

Yes this script hits the website every 10 seconds checking to see if the limit message is not on the page and play a message if it is not. I was sufficiently amused by this that I gisted it and posted to twitter. Funny thing is with in a minute I had been retweeted by Joshua Holbrook the support lead for Nodejitsu and got the following response from NodeKohai the IRC bot for the Nodejistu channel.

NotMyself Very nice! Now come join ‪#nodejitsu‬ on freenode to claim your prize!

You see sometimes being a smart ass is a bonus. It gets you free things! Also here is a quick video showing the script in action.

Share this story

Bobby Johnson

About Author

I am a passionate engineer with an interest in shipping quality software, building strong collaborative teams and continuous improvement of my skills, team and the product.

comments powered by Disqus
Back to top