Deploy Twitter bot on Heroku

neer17

Neeraj Sewani

Posted on May 31, 2021

Deploy Twitter bot on Heroku

In part 1 of this post, we have made a Twitter bot that greets followers and people who like our tweets but it was dependent on our local machine. So, in this post let's get rid of it and push it on Heroku.

Heroku bestow the functionality to make a Node app a Worker which would run continuously as opposed to a Web app that would be put to sleep if not visited for a brief period of time.

Step-0: Make a Heroku app, then we can deploy the app using either Heroku CLI or attaching Github to it. Here, I am gonna use Heroku CLI.

Step-1: Add a Procfile to make our app a Worker. Simply make a file with the name Procfile add it to the root and add the following code in it:

worker: npm start
Enter fullscreen mode Exit fullscreen mode

And modify the start script to "start": "node bot.js"

Step-2: Push the app to heroku by following the steps:

  • Install Git form here
  • Install Heroku CLI from here
  • Commit your changes using Git

    
      cd myapp
      git init
      Initialized empty Git repository in .git/
      git add .
      git commit -m "My first commit"
    
    
  • Then create a Heroku app using heroku create twitter-bot-2021, this would also add a remote to you repository. Check the remote using git remote -v. This should show a Herko remote.

  • Now open the app by login in to the Heroku in order to put environment variables there as we cannot push .env file for security reasons.

  • Get the app URL by opening up the app using open app option from inside the app dashboard.

  • Then go to settings and click on Reveal Config Vars and insert the environment variables present in your .env file.

  • Now, finally deploy the code to Heroku using git push heroku master:main, if you are on the main branch in your local git repo then simply do git push heroku main.

  • Checkout these docs related to deployment in case you are stuck somewhere.

  • Check the dashboard of the app, it should show a successful build in green.

  • Now, finally check the bot by following it form some other account, you should get the DM from the bot.

And you have done it.

💖 💪 🙅 🚩
neer17
Neeraj Sewani

Posted on May 31, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Deploy Twitter bot on Heroku
heroku Deploy Twitter bot on Heroku

May 31, 2021