This application allows users to perform CRUD operations on to-do items. Users can:
-
Create a to-do item (C) -> /tasks post
-
Read the list of to-do items (R) -> /tasks get
-
Update a to-do item to mark it as complete or incomplete (U) -> /tasks/:id put
-
Delete a to-do item (D) -> /tasks/:id delete
- using restfulAPI : address + http method
- tasks post
- tasks get
- tasks put
- tasks delete
- using restfulAPI : address + http method
-
Initial Setup
- Set up npm
- Use Express for the serverss
- Use Mongoose for database interaction
- Create an app listener
-
Define Routes
- Define the necessary routes for CRUD operations
-
Database Schema
- Define the database schema for to-do items
const todoSchema = new mongoose.Schema({ task: { type: String, required: true, }, isComplete: { type: Boolean, default: false, }, });
-
Functionality
- Implement CRUD operations
- Implement User Registration
- Accept email, password, and username
- Store received information in the database
- Encrypt passwords before storing
- Implement User Login
- Enter email and password and send
- Check in the database if there is a user with the corresponding email and password
- If not, login fails
- If yes, user information + token
- The frontend stores this information
-
Testing
- Use Postman for testing API endpoints
- Node.js
- npm
- MongoDB Atlas: Use MongoDB Atlas for database deployment.
- AWS Elastic Beanstalk: Deploy the backend using AWS Elastic Beanstalk.
- Heroku: Alternatively, you can deploy the backend on Heroku.
- Deploy the frontend using your preferred hosting service (e.g., Vercel, Netlify, AWS S3, etc.).
- Ensure to thoroughly test the application, both backend and frontend functionalities, before and after deployment.
I encountered a gateway error:
2024/05/23 09:14:17 [error] 2117#2117: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 50.175.105.250, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "todo-mayster.us-east-2.elasticbeanstalk.com"
The server was configured to use port 5050. To fix this, I updated the server configuration to:
app.listen(process.env.PORT || 5000, () => {
console.log("server on");
});
userController.loginWithEmail= async(req,res)=>{
try{
const {email, password} = req.body
const user = await User.findOne({email}, "-createdAt -updatedAt -__v");
if(user){
const isMatch = bcrypt.compareSync(password, user.password);
if(isMatch){
const token = user.generateToken();
return res.status(200).json({status:"success", user, token})
}
}
throw new Error("userId or password is incorrect!")
}catch(err){
res.status(400).json({status: "fail~", err});
}
};
I changed the password to something other than '0000'