For a while, nobody in my circle of friends was talking about crypto. But now, prices are shooting up. And, it was the main conversation topic at my Christmas dinner. I thought it would be cool to create a NodeJS project that will send an automated text message when BTC reaches $30,000. Let's dive in! Getting the current BTC price First steps first, let's set up a new Node project. mkdir crypto-notifier cd crypto-notifier touch index.js npm init Next, I'm going to scrape the current BTC price from . coinmarketcap Let's install the package. axios npm i axios Let's update the file to get the Coinmarketcap website. index.js axios = ( ) axios.get( ) .then( { .log(response.data); }) const require 'axios' 'https://coinmarketcap.com/' ( ) => response console For now it just prints the raw html, let's see if it works! node index.js // A lot of HTML gibberish Alright, we are able to get the raw HTML. Now, let's extract the current BTC price from it. First I install the package. jsdom npm i jsdom Then, let's update the index.js file to use the jsdom package. axios = ( ) jsdom = ( ); { JSDOM } = jsdom; axios.get( ) .then( { { } = ( JSDOM(response.data)).window; btcElement = .querySelector( ) price = btcElement.textContent.trim(); .log( + price); }) const require 'axios' const require "jsdom" const 'https://coinmarketcap.com/' ( ) => response // Create the JSDom object const document new // The query selector looks complex, but I simply grabbed it using the Chrome dev tools. const document "#__next > div > div.sc-57oli2-0.dEqHl.cmc-body-wrapper > div > div > div.tableWrapper___3utdq > table > tbody > tr:nth-child(1) > td:nth-child(4) > div > a" const console "BTC: " And when running this it shows the correct BTC price. 💰 node index.js BTC: $27,261.65 Checking if the price's greater than 30K Right now the program just prints the BTC price. Let's improve it by converting the price to a number and checking if it's greater than 30K. priceAsText = btcElement.textContent.trim(); priceAsNumber = ( priceAsText.replace( , ).replace( , ) ) (priceAsNumber >= ) { .log( ) } { .log( ) } const // Convert the price to a number. const parseFloat "," "" "$" "" // Check if it's greater than 30K. if 30000 console "BTC reached 30K. Sending a text message!" else console "BTC < 30K. Doing nothing." And when I run the program it prints out the correct response. node index.js BTC < 30K. Doing nothing. A thing to note is that we are currently scraping Coinmarketcap. If we were to run this program every minute they probably wouldn't be too happy. They also have an API that you can use, but that's not 100% free. An alternative is to use a scraper API such as to avoid getting blocked. scraperbox Sending a text message I'm going to use the to send a text message. messagebird API First let's install the Messagebird package. npm install messagebird Next, let's import the package. messagebird = ( )( ); const require 'messagebird' 'YOUR_API_TOKEN' And, let's send the actual text message when BTC is greater than 30K. (priceAsNumber >= ) { .log( ) messagebird.messages.create({ : , : [ ], : }, { (err) { err; } .log( ) }) } { .log( ) } if 30000 console "BTC reached 30K. Sending a text message!" originator '31612345678' recipients '31612345678' body `FOMO, BTC IS Buy Buy Buy!` ${priceAsText} ( ) function err, response if // If something goes wrong, throw the error throw console "Text message send" else console "BTC < 30K. Doing nothing." Great, now the program will send a text message if BTC hits 30k. Running the program every minute There is still one problem. We must run the program every minute to keep checking for price changes. We can do this a number of ways, but one of the easiest ways is to use ! crontabs Simply edit the crontab file with the following command. crontab -e And add the crontab to run the program every minute. * * * * * node /Users/dirk/crypto-notifier/index.js And that's it, it will now run the program every minute! 🔥 Conclusion We've set up a program that checks Coinmarketcap every minute. It will send a text message if the BTC price is greater than 30K. It's not the most practical program, but it was definitely fun to build. Happy coding! 👨💻