Backend Development Takeaways: Server Setup, JWT Auth, MongoDB

🚀 Today I spent time diving deep into Backend Development and honestly my mind is blown. Here's everything I learned in one post 👇 🔷 SERVER SETUP (server.js) Every backend starts with one entry point. server.js is where everything connects — database, middleware, routes. Nothing runs until MongoDB connects first. 🔷 MIDDLEWARE = THE CONVEYOR BELT Every request passes through middleware in order: • Logger → saves every request to a log file • CORS → tells the browser "yes, this frontend is allowed" • express.urlencoded → reads HTML form data • express.json → reads JSON data from React/axios • cookieParser → reads cookies (refresh token!) 🔷 CORS Without CORS your frontend and backend can't even talk to each other. CORS is basically your backend giving the browser permission to interact. 🔷 JWT AUTHENTICATION FLOW This was the biggest learning today: ✅ Register → account created, password hashed ✅ Login → get Access Token + Refresh Token ✅ Access Token → lives in React memory, expires in 15 mins ✅ Refresh Token → hidden in httpOnly cookie, lives in DB ✅ Token expires → cookie auto sends → new Access Token generated ✅ Logout → cookie cleared, token deleted from DB 🔷 WHY TWO TOKENS? Access Token gets stolen? It dies in 15 mins ✅ Refresh Token gets stolen? Delete it from database instantly ✅ 🔷 SESSIONS vs JWT Sessions store everything on the server — safe but slow. JWT carries data inside the token — fast and scalable. Banking apps prefer sessions. APIs and mobile apps prefer JWT. 🔷 AXIOS vs FETCH fetch = built in browser tool, more manual work axios = library that makes HTTP requests cleaner Just like how React makes JavaScript easier, axios makes fetch easier! 🔷 MONGOOSE vs MONGODB MongoDB = the actual database Mongoose = the tool that makes talking to MongoDB easy You always use BOTH together! 🔷 .env FILE Stores all secrets — database passwords, JWT secret keys, port numbers. Never goes to GitHub thanks to .gitignore 🔐 🔷 MODELS Every model is a blueprint connected to MongoDB. User.js → users collection Employee.js → employees collection Biggest takeaway today? Every tool exists to solve a specific problem. Once you understand the PROBLEM, the tool makes total sense. 💡 Still a beginner but connecting the dots every single day! 💪 #BackendDevelopment #NodeJS #ExpressJS #JWT #MongoDB #100DaysOfCode #WebDevelopment #LearningInPublic

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories