Backend API for the Blog Post Angular application.
npm install- Open the
.envfile in the server folder - Replace
<YOUR_PASSWORD_HERE>with your actual MongoDB password - Update other settings if needed
Development mode (with auto-restart):
npm run devProduction mode:
npm startThe server will run on http://localhost:3000
- POST
/v1/users/register - Body:
{ "username": "johndoe", "password": "password123", "name": "John Doe", "email": "john@example.com" (optional) } - Response:
{ "success": true, "data": { "access_token": "jwt_token_here", "refresh_token": "refresh_token_here", "user": { ... } } }
- POST
/v1/auth/login - Body:
{ "username": "johndoe", "password": "password123" } - Response: Same as register
- POST
/v1/auth/refresh-token - Body:
{ "refresh_token": "refresh_token_here" }
- POST
/v1/auth/logout - Headers:
Authorization: Bearer {access_token}
- GET
/v1/users/me - Headers:
Authorization: Bearer {access_token}
- PUT
/v1/users/me - Headers:
Authorization: Bearer {access_token} - Body:
{ "personal_info": { "fullName": "John Doe Updated", "bio": "My bio" }, "social_links": { "twitter": "https://twitter.com/johndoe" } }
- GET
/health
- ✅ Password hashing with bcrypt
- ✅ JWT authentication with access & refresh tokens
- ✅ Environment variables for sensitive data
- ✅ CORS enabled
- ✅ Input validation
This project is deployed to a Google Cloud Compute Engine instance using Docker and GitHub Actions.
- Trigger: Any code pushed to the
mainbranch automatically triggers.github/workflows/ci-cd.yml. - Package: GitHub Actions creates a compressed
.tararchive of the codebase (excludingnode_modulesand.git). - Transfer: It securely copies the archive to the server at
~/app-blog/serverusing SCP. - Deploy: It logs into the server via SSH, extracts the code, and runs
docker compose -f docker-compose.prod.yml up -d --build. - Clean up: Old Docker images are pruned to save disk space.
To view deployment logs, check the "Actions" tab in your GitHub repository.
You can access the server terminal using one of two methods:
Method 1: Google Cloud Console (Easiest)
- Open the Google Cloud Console.
- Go to Compute Engine > VM instances.
- Click the SSH button next to your instance.
Method 2: Local Terminal If your SSH keys are set up locally:
ssh saapril1177@<YOUR_SERVER_IP>Once logged into your server terminal, use these commands to manage the application:
1. Navigate to the App Directory:
cd ~/app-blog/server/docker2. View Running Containers:
docker compose -f docker-compose.prod.yml ps3. View Live Logs:
# View all logs
docker compose -f docker-compose.prod.yml logs -f
# View only the API logs
docker compose -f docker-compose.prod.yml logs -f api(Press Ctrl + C to exit logs)
4. Restart the Application:
docker compose -f docker-compose.prod.yml restart5. Manually Deploy (Without GitHub):
docker compose -f docker-compose.prod.yml down
docker compose -f docker-compose.prod.yml up -d --build