This repo is used by the Bits of Good Bootcamp to build a Twitter bot that demonstrates important concepts related to Node.js, APIs, and database technologies used by Bits of Good project teams.
Learn more about Bits of Good and our Bootcamp at bitsofgood.org!
For each challenge listed below, there is a corresponding branch that will have the solution to that challenge. Each step builds on the one before it, so make sure that you go one challenge at a time! When you think you have it, go ahead and compare your repository/code to the solution branch and see how you did.
-
Initialize this repository as an NPM package
-
Install each of the following packages:
express
twitter
body-parser
dotenv
-
Get an Express server up and running with an endpoint for
POST
requests to the/tweets
path -
Read about Express middleware
-
Using the
express.static
middleware, get Express to use thepublic/
folder in this repository so that you can visit thetweet/index.html
page from your browser by visitinghttp://localhost:3000/tweet
- Hint: If a folder has
index.html
inside of it, you can access that file from your browser by the folder name!
- Hint: If a folder has
-
Using the
body-parser
NPM documentation as a reference, pick a middleware from thebody-parser
package that will allow you to easily access form data in your handler functions- Hint: Form data is URL-encoded!
-
Ask Max for the API keys you need to use the Twitter API. Put what he gives you in a new
.env
file in this repository. -
Read this Medium article on what environment variables are and why we use them.
-
Use the
dotenv
NPM docs to figure out how to load in environment variables from the.env
file in your repo. -
Use the
twitter
NPM docs to create anauth
object that contains all the API keys you stored in your environment variables, and initialize the Twitter client with that auth object. -
Write
sendTweet
function. Have it send a tweet using the Twitter API statuses/update endpoint! -
Fill in your Express handler for POST requests to
/tweet
so that it...- gets the tweet text from the
public/tweets/index.html
form (Hint: the variable name of the form tweet text istweet
) - posts a Tweet with that text
- only sends the Tweet and returns 200 OK if the tweet is at least 3 characters long
- (challenge) redirects to the Twitter bot http://twitter.com/bog_bot
- gets the tweet text from the
You're done! You've built the Twitter bot.