Get your Social Media Backend API up and running in 5 minutes!
- Node.js (v14 or higher) - Download here
- PostgreSQL (v12 or higher) - Setup guide
- Git - Download here
git clone <your-repository-url>
cd express-postgres-apinpm installThis will install all required packages:
- Express.js (web framework)
- Sequelize (ORM)
- PostgreSQL driver
- JWT for authentication
- bcrypt for password hashing
- And more...
# Connect to PostgreSQL
psql -U postgres
# Create database
CREATE DATABASE social_media_db;
# Exit
\qdocker run --name postgres-social-media \
-e POSTGRES_DB=social_media_db \
-e POSTGRES_PASSWORD=postgres \
-p 5432:5432 \
-d postgres:15-alpine📖 Need help? See DATABASE_SETUP.md
Create a .env file in the root directory:
# Copy the example file
cp .env.example .envUpdate the values in .env:
# Server
PORT=3000
NODE_ENV=development
# Database
DB_HOST=localhost
DB_PORT=5432
DB_NAME=social_media_db
DB_USER=postgres
DB_PASSWORD=your_password_here
# JWT
JWT_SECRET=your_super_secret_key_change_this
JWT_EXPIRE=7d
# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100JWT_SECRET to a strong random string!
# Generate a random secret (Node.js)
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"# Development mode (with auto-restart)
npm run dev
# Production mode
npm startYou should see:
✅ Database connection established successfully.
✅ Database synchronized successfully.
🚀 ============================================
🚀 Server is running on port 3000
🚀 Environment: development
🚀 API URL: http://localhost:3000
🚀 ============================================
curl http://localhost:3000Expected response:
{
"success": true,
"message": "Social Media API is running",
"version": "1.0.0"
}curl -X POST http://localhost:3000/api/auth/register \
-H "Content-Type: application/json" \
-d "{
\"username\": \"testuser\",
\"email\": \"test@example.com\",
\"password\": \"Test123!\",
\"fullName\": \"Test User\"
}"You'll receive a JWT token in the response. Copy it for the next steps!
curl -X POST http://localhost:3000/api/posts \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-H "Content-Type: application/json" \
-d "{
\"title\": \"My First Post\",
\"content\": \"This is my first post on the social media platform!\"
}"curl http://localhost:3000/api/postsReady to deploy? Check out:
-
Use a REST Client
- Install Thunder Client (VS Code extension)
- Or use Postman
-
View Database
-
Monitor Logs
# Watch logs in development npm run dev # Or use nodemon directly npx nodemon src/server.js
# Windows
netstat -ano | findstr :3000
taskkill /PID <PID> /F
# macOS/Linux
lsof -ti:3000 | xargs kill -9- Check if PostgreSQL is running
- Verify credentials in
.env - Ensure database exists
- Check firewall settings
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register user |
| POST | /api/auth/login |
Login user |
| GET | /api/auth/me |
Get current user |
| GET | /api/posts |
Get all posts |
| POST | /api/posts |
Create post (auth) |
| GET | /api/posts/:id |
Get single post |
| PUT | /api/posts/:id |
Update post (auth) |
| DELETE | /api/posts/:id |
Delete post (auth) |
| GET | /api/comments/post/:postId |
Get comments |
| POST | /api/comments/post/:postId |
Add comment (auth) |
| POST | /api/likes/post/:postId |
Like post (auth) |
| DELETE | /api/likes/post/:postId |
Unlike post (auth) |
npm start # Start production server
npm run dev # Start development server (auto-reload)
npm test # Run tests (when implemented)- 📖 Check the full README
- 🔍 Search GitHub Issues
- 💬 Ask for help in discussions
You're now running a complete social media backend with:
- ✅ User authentication (JWT)
- ✅ Post management (CRUD)
- ✅ Comments system
- ✅ Likes functionality
- ✅ Input validation
- ✅ Error handling
- ✅ Security features
- ✅ Rate limiting
Happy coding! 🚀