Deploying Node.js to AWS EC2: Lessons Learned

🚀 Successfully deployed my first Node.js backend to AWS EC2! After years of running apps on localhost, I finally took the leap into cloud deployment. Here's what the journey taught me: 𝗪𝗵𝗮𝘁 𝗜 𝗕𝘂𝗶𝗹𝘁: Full-stack fitness tracking platform with AI-powered workout coaching Backend API: Node.js + Express Database: MongoDB Atlas AI: Google Gemini with RAG for personalized recommendations 𝗧𝗵𝗲 𝗗𝗲𝗽𝗹𝗼𝘆𝗺𝗲𝗻𝘁 𝗣𝗿𝗼𝗰𝗲𝘀𝘀: ✅ Launched EC2 instance (Ubuntu t3.micro - free tier!) ✅ Configured Security Groups for network access ✅ Set up SSH key-based authentication ✅ Installed Node.js and dependencies ✅ Implemented PM2 for process management ✅ Configured auto-restart on server reboot 𝗞𝗲𝘆 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴𝘀: • SSH keys > passwords • Use environment variables for secrets (never commit .env) 💡 Process Management is Critical Without PM2, the app stops when SSH disconnects With PM2, it keeps running in the background 💡 Cloud Basics Matter Understanding ports, networking, and instance lifecycle is key 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲𝘀 𝗙𝗮𝗰𝗲𝗱: ❌ First attempt: Forgot to open port 5000 in Security Groups Lesson: Network access needs proper configuration ❌ PM2 stopped working after reboot Lesson: Always run pm2 startup and pm2 save 𝗡𝗲𝘅𝘁 𝗨𝗽: 📦 Deploying Angular frontend 🔄 Setting up CI/CD pipeline 🔒 Adding HTTPS for secure connections 𝗙𝗼𝗿 𝗙𝗲𝗹𝗹𝗼𝘄 𝗗𝗲𝘃𝗲𝗹𝗼𝗽𝗲𝗿𝘀: If you’ve been thinking about trying cloud deployment, just start. Launch an instance, experiment, break things, and learn along the way. Also curious — for those who’ve worked with different platforms, which do you prefer for beginners: AWS, Azure, or something else? #CloudComputing #WebDevelopment #FullStackDeveloper #DevOps #NodeJS #LearningInPublic #SoftwareEngineering #BuildInPublic

To view or add a comment, sign in

Explore content categories