MongoDB + Express + React + Node.js
Video | Blog | Code |
Pre-requisites:
- Node.js version 8.17.0 (lts/carbon)
- Nodemon - Install
nodemon
globally or usenpx nodemon
.
Note: You will need to run
sudo npm install -g --force nodemon
to get macOS terminal to find nodemon.
Tip: To run the backend
server.js
file, you may runnpx nodemon server
without modifying thepackage.json
file.
- Run
npx create-react-app mern-exercise-tracker
to create the folder/React project
- Change directory into newly created folder
cd mern-exercise-tracker
- Create new folder
backend
and change into it - Run
npm init -y
to create npm scaffold project with default values - Create a new file called
server.js
- Paste boilerplate express code with mongoose/cors/dotenv lines
- Create
.env
file in backend folder and make sure the mongoose URI is set properly (note: make sure to change URI tolocalhost
if running locally). - Make sure the root
.gitignore
file is skipping the newly created.env
file and thenode_modules
folder within the backend folder - In the backend folder, create a new folder called
models
with two filesexercise.model.js
anduser.model.js
- Input the schema into each respective model file
- In the backend folder, create a new folder called
routes
with two filesexercises.js
andusers.js
- Update
server.js
to use the newly created routes - Input the routes into the newly created routes files. Include advanced features like update by ID and deleting exercises
You are done with the backend (for the video section)! Skip to 43:37 in the video to proceed with the frontend