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.
Go to the Github Repo for the base project, click Code, and copy the Clone url:
<https://github.com/freeCodeCamp/boilerplate-project-exercisetracker.git>
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
After the project is imported, click 'Share' and copy the live app link. This will be the app url you will submit.
IMPORTANT - Update MongoDb and Mongoose to the latest version, replace the versions in the package.json to the version from their npm pages:
Your Package.json should look something like this with at least these version numbers:
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!!
Set up a MongoDB cluster following the instructions here:
Store the password in an environment variable in Glitch like this:
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
Replace the connect line in the server.js:
With this:
mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true });
Check that there are no errors after this.
See this guide for more help: