- Set up the Project folder
- Mkdir mern-goal
- Cd mean-goal
- Mkdir backend
- Make life sever.js
- Mkdir backend
- In mean-goal
- Npm init
- Change entry point to be
- server.js
- Change entry point to be
- Add .gitignore
- .env
- node_modules
- Npm I express
- Npm init
- Created an account with email
- Connect with the mongosdb shell
- Install mongoshon Browser
- Collections (tables)
- Collection of objects [Json obj]
- Create collection (db name and collection (tables))
- Connect
- Choose …. Compass
- Copy the connection string
- Click on connectOn Software
- Choose …. Compass
- Open the compass software
- New connection
- mongodb+srv://byusa:@cluster0.gnh445e.mongodb.net/test
- Back to the browser
- Connect
- Connect your application
- Copy that string too
- Connect your application
- In .env add this
- mongodb+srv://byusa:@cluster0.gnh445e.mongodb.net/?retryWrites=true&w=majority
- Code
- Routes
- userRoutes.js
- route.post(‘/login’, registerUser)
- route.post(‘/login’, loginUser)
- route.get(‘/me’, protect, getMe)
- goalRoutes.js (protect those api too)
- In this case you need to a token to do CRUD operations
- userRoutes.js
- Controllers
- userController.js
- registerUser
- loginUser
- getMe
- userController.js
- Models
- goalModel.js
- Config
- Middleware
- authmiddlerware
- protect
- authmiddlerware
- Severs.js
- app.use('/api/users', require('./routes/userRoutes'))
- Routes
- Packages to install
- npm i bcryptjs
- npm i jsonwebtoken