Creating a Twitter Bot with Node.js

Created at 2016-08-02 Updated at 2016-11-02 Tag Javascript / Node / Twitter / API

I am a huge fan of the television program Shark Tank. To have more fun watching it, I decided to make a twitter bot that would retweet anything that included the searchable hashtag #SharkTank.

This wasn’t a very hard of a project, there are already many tutorials and boiler plates for getting a bot up and running on Node.js with the Twitter API. You can find the source code to my bot here.

Clone the git repo git clone https://github.com/JacksonJS/sharkTankBot.git and setup your Twitter account for apps, and plugin your credentials into config.js

1
2
3
4
5
6
module.exports = {
consumer_key: 'use',
consumer_secret: 'your',
access_token: 'own',
access_token_secret: 'tokens&keys'
}

Run npm install in your root folder, allow the dependencies to be downloaded, and then run:

1
node bot.js

Super easy!


There are several guides to help you start making a bot, and I used https://github.com/nisrulz/twitterbot-nodejs as a starting point for @SharkTankBot.

Info for using the Twitter API Client for node is located here

Edit: I am now using the forever package for node to keep this bot from crashing. To use, run npm install -g forever.

To start the bot, while in the bot root directory, run forever start --spinSleepTime 10000 bot.js.

Instead of writing to the console, our logs will go somewhere in ~/.forever. To locate the log for your currently running node project, run forever list.

If you would like to see the live updates of logs, run tail -f <logfile>.


I will update this post as I add new features to the bot. Have fun, and stay safe!

😎

Site by Jackson Stokes

Hide