Hoot Back-End Setup

Setup

Open your Terminal application and navigate to your ~/code/ga/lectures directory:

cd ~/code/ga/lectures

Cloning the Auth boilerplate

This lecture uses the Express API JWT Auth Template as starter code. The template includes code to authenticate users with JWT tokens.

Navigate to the Express API JWT Auth Template and clone the repository to your machine:

git clone https://git.generalassemb.ly/modular-curriculum-all-courses/express-api-jwt-auth-template.git

Once we have the repository on our machines, we can change the name of the directory to 'express-api-hoot-back-end':

mv express-api-jwt-auth-template express-api-hoot-back-end

Next, cd into your renamed directory:

cd express-api-hoot-back-end

Finally, remove the existing .git information from this template:

rm -rf .git

Removing the .git info is important as this is just a starter template provided by GA. You do not need the existing git history for this project.

GitHub setup

To add this project to GitHub, initialize a new Git repository:

git init
git add .
git commit -m "init commit"

Make a new repository on GitHub named express-api-hoot-back-end.

Link your local project to your remote GitHub repo:

git remote add origin https://github.com/<github-username>/express-api-hoot-back-end.git
git push origin main

🚨 Do not copy the above command. It will not work. Your GitHub username will replace <github-username> (including the < and >) in the URL above.

Open the project’s folder in your code editor:

code .

Install dependencies

Next, you will want to install all of the packages listed in package.json

npm i

Create your .env

Run the following command in your terminal:

touch .env

Lastly, we want to add a MONGODB_URI and a JWT_SECRET.

Add the following secret keys to your application:

MONGODB_URI=mongodb+srv://<username>:<password>@sei-w0kys.azure.mongodb.net/hoot?retryWrites=true
JWT_SECRET=supersecret

If you are unsure of where to obtain your MongoDB URI, please refer to the MongoDB Atlas Setup Lab.

Run the application

If you check the package.json of your starter code, you’ll see a script has been added to run the application using the dev dependency nodemon.

Start the application with the following command:

npm run dev

Happy Coding!