- Ensure that you have Node installed on your computer. Run the command
node --version
to see if it is installed. - If Node is not installed, you can install it here.
- Clone the repository onto your local machine.
- Create a MongoDB Atlas account here.
- Go to the inbox of the email you signed up with and look for an email to verify your account.
- Once your account is verified, you will be redirected to a page and answer a few questions (your answers to these questions are not imporant).
- From there, you will be asked to select a plan for your database. Selet *M0 (Free)_ and click Create.
- Completing 5 will bring you to Security QuickStart, where you'll set up credentials to access your database. Create a new user (make sure to save the username and password somewhere).
- MongoDB will place your default IP Address on the access list. Click Finish and Close.
- Your database will take a couple minutes to create. Once it's finish, navigate to the Database Section on Atlas and click Connect on Cluster0. Then click Drivers. Under section 3 (Add your connection string to application code), copy the URI shown.
- In this repository, navigate to the
.env.example
file in /backend. Rename the file to .env and then setMONGO_URI=mongodb+srv://<username>:<password>@cluster0.bwltaes.mongodb.net/?retryWrites=true&w=majority
with the appropriate username and password (that you created for the user in step 6).
We'll be testing our API with a platform called Postman. Download the desktop verson here.
- After performing the steps above,
cd
into the /backend directory and runnpm install
ornpm i
- To start the application, run
npm run dev
.
In the workshop, we will create a simple REST API with Node.js Express for managing information about different T4SG teams and members.
In \models, you should see two files that define schemas for a Member and Team collection. These schemas are defined using mongoose, which is a JavaScript object-oriented library that creates a connection between our Node.js app and our MongoDB database. With this library we can define schemas, validation rules, and also perform CRUD processes on our database.
Overall, we'll define the endpoints of our API in views. We'll create the following endpoints:
/create-team
: adds a new team to the database./get-teams
: retrieves all the teams in the database/edit-team/:id
: edits the team with objectIDid
with a given payload/delete-team/:id
: removes the team with objectIDid
/add-member
: adds a T4SG member/get-members
: gets all T4SG members/edit-member/:id
: edits the information of member with objectIDid
/delete-member/:id
: removes member with objectIDid
from database