1st Backend_app with mongoDB
Day-5 of learning WebDev #Backend_Engineering Day-5 In the past 3 days, what I have learned and practised: MongoDB & Mongoose →understood MongoDB basics: a NoSQL database that stores data as JSON-like documents. → Learned CRUD operations: Create, Read, Update, Delete. → Realized updates can be full replacement or partial. → Learned filters in updates (_id + userId) to make sure only the intended document is changed. → Practiced using Mongoose to connect, define schemas, and create models (UserModel, TodoModel). → Learned ObjectId usage for uniquely identifying documents and linking todos to users Password Security with bcrypt → Problem: Storing plain-text passwords is dangerous what if the DB leaks, attackers can use them. → Solution: Hash passwords before storing. Hashing is one-way, we can’t reverse it. → New issue: Same passwords give same hash → rainbow table attacks. → Fix: Salt the password before hashing (hash(password + salt)), so identical passwords produce different hashes. → Why bcrypt: 1)Automatically salts passwords 2)Intentionally slow → slows brute-force attacks Zod Validation → Used zod library for request validation. → Validated user signup fields: email format, name, password complexity (uppercase, lowercase, number, special char). → Learned that safeParse gives clear errors when validation fails, improving backend security and reliability. Express.js & Todo App Project → Built a full backend for a todo app using Express.js. → Learned RESTful principles: POST to create, GET to read, PATCH to update partially. → Routes created: Signup: /signup it validates input, hashes password, stores user. Signin: /signin it verifies user credentials, returns JWT token. Create Todo: /todo authenticated route, saves todo linked to userId. Update Todo: /update/:todoId it uses PATCH and $set to change only title.Ensures userId matches, preventing unauthorized changes. Mark Todo as Done: /markasDone/:todoId it uses PATCH and $set to update done boolean