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
Get Todos: /todos authenticated route, returns all todos for the logged-in user.
Libraries Used Today
→ Express.js → Routing and middleware
→ Mongoose → MongoDB interaction, schemas, models
→ bcrypt → Password hashing and security
→ jsonwebtoken (JWT) → Stateless authentication
→ Zod → Input validation
→ dotenv → Environment configuration for secrets (MONGO_URL, JWT_SECRET)
#NodeJS #ExpressJS #MongoDB #Mongoose #FullStackDevelopment #BackendDevelopment #APIDevelopment #RESTAPI #WebDevelopment #JavaScript
2
3 comments
Shoaib Khan
3
1st Backend_app with mongoDB
powered by
Make $1k-$10k in 30 days
skool.com/make-1k-5k-in-30-days-8449
Media Valley School is the fastest way to hit $1K/month with freelancing or agency work. Guaranteed.
Land your first $1K month in 30 days
Build your own community
Bring people together around your passion and get paid.
Powered by