https://youtu.be/ANfJ0oGL2Pk

This is a full walkthrough for the Exercise Tracker project on freeCodeCamp. We connect to a MongoDB database and set up some models for storing users and exercise sessions. Then we can create express routes to add and retrieve data from the database which the user can access through form POST and url GET routes.

Notes

0:00 - Project Setup

  1. Go to the Github Repo for the base project, click Code, and copy the Clone url:

    <https://github.com/freeCodeCamp/boilerplate-project-exercisetracker.git>
    

    freeCodeCamp/boilerplate-project-exercisetracker

  2. Go to Glitch, Sign In, Click 'New Project', Import from Github, and then paste and submit the Git URL

    Glitch: The friendly community where everyone builds the web

  3. After the project is imported, click 'Share' and copy the live app link. This will be the app url you will submit.

  4. IMPORTANT - Update MongoDb and Mongoose to the latest version, replace the versions in the package.json to the version from their npm pages:

    mongodb

    mongoose

    Your Package.json should look something like this with at least these version numbers:

    https://s3-us-west-2.amazonaws.com/secure.notion-static.com/6faed0f9-6896-4eac-b15b-0575fb04bf48/Untitled.png

    Open the terminal and run the following command to make sure everything is updated:

    npm install
    

    The following steps won't work if you don't do this!!

02:20 - Database Connection Setup

  1. Set up a MongoDB cluster following the instructions here:

    Introduction to the MongoDB and Mongoose Challenges

  2. Store the password in an environment variable in Glitch like this:

    https://s3-us-west-2.amazonaws.com/secure.notion-static.com/d8e08b1f-fc76-42e9-b202-2bca6d8331a3/Annotation_2020-07-16_114843.png

  3. Create a uri string variable in your code like this, filling in your details:

    let uri = 'mongodb+srv://<USERNAME>:' + process.env.PW + '@xxxxxx.xxxxx.mongodb.net/<DATABASE>?retryWrites=true&w=majority'
    

    The password will be added from the environment variables

  4. Replace the connect line in the server.js:

    https://s3-us-west-2.amazonaws.com/secure.notion-static.com/1e74fbff-736e-48a1-9283-16ee57a7caeb/Untitled.png

    With this:

    mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true });
    

Check that there are no errors after this.

See this guide for more help:

Install and Set Up Mongoose

05:42 - Creating the Models