Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 29, 2019 09:09 am GMT

Is this a 1.000,00 worth Node script?

So the story begins with one of my favourite Youtube channels. A few days ago, they've published a new video announcing that they will soon reach their 100k subscriber and on that occasion will give out a 1.000,00 voucher which the person can then spend on new equipment.
That's a lot of money! Especially if you're, like me, living in Croatia. We're talking about approximate 20% more than an average monthly salary here.


I must admit, after I heard the announcement I was immediately hooked. I paused the video and started thinking of ways to become that 100k subscriber and win the voucher. What I figured out next is that manually checking the number of subscribers and waiting for the right moment to hit the subscribe button won't bring me any luck. I needed a machine to do that work for me if I want to be faster than others.

Fast as machine

After a short brainstorming session I came up with an easy solution and the only thing I needed was Youtube API and a little bit of Node. Solution is pretty straightforward: we had to know how many subscribers the channel has so when it reaches its 99.999 subscriber we would need to subscribe.


If you're already thinking about implementation then you know that we'll need setInterval or setTimeout so we can repeatedly check the number of subscribers.

The only limitation we have here is YouTube Data API quota usage. We get default quota allocation of 10.000 units per day which means that each request will cost us some units.

In our case, if we want to get a number of channel subscribers we need to do a request to and that request will cost us 3 units. You can calculate your quota cost using Youtube Quota Calculator.

If we check the subscribers count every second we'll drain our quota by running our script for 55 minutes which is just not enough; we want our script to run longer so that we don't miss out on our chance. The only solution for this limitation is to use a different interval delay depending on the number of subscribers. That means that we'll perform requests more frequently as the number of subscribers approaches 100k. In the beginning we'll start with one request per hour and then we'll get all the way down to 300 milliseconds.


Check the solution in this repo below and try it out.

Youtube Subscriber

If you want to know why this repo was created read this story about 1.000,00 voucher.


Clone repository

$ git clone

cd into directory

$ cd youtube-subscriber

Install NPM dependencies

$ npm install


Before running the script you should update variables inside of config.js file.

Update following variables:

  • channelId
  • client_secret
  • client_id

Run the server

After updating config variables you can run server and let him do the magic.

$ node main.js


After I've finished with the implementation, I continued watching the video where they announce their bounty. In that moment I knew I f***** up. It was never about being the 100Kth subscriber, it was about visiting their social profiles and participating in the prize game where the winner will be randomly chosen.

So here I am, with a published script and without a 1.000,00 voucher. But let's look at the bright side - at least I've learned something new and maybe, in the future, this script helps someone actually win the voucher, who knows.
Until then, happy coding!

Original Link:

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To