# π Deploy NestJS Application on GCP for Free
## 1οΈβ£ Create a Google Cloud Account
- Go to Google Cloud Console
- Sign up for $300 free credits (valid for 90 days).
- Enable Billing (required even for free-tier services).
## 2οΈβ£ Install Required CLI Tools
# Install Google Cloud SDK
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-441.0.0-linux-x86_64.tar.gz
tar -xvzf google-cloud-sdk-*.tar.gz
./google-cloud-sdk/install.sh
# Restart terminal and initialize GCP CLI
gcloud init
- Authenticate with your Google account.
- Set your default project and region.
## 3οΈβ£ Enable Required GCP Services
gcloud services enable run.googleapis.com containerregistry.googleapis.com artifactregistry.googleapis.com
## 4οΈβ£ Clone Your GitHub Repository
git clone <YOUR_GITHUB_REPO_URL>
cd <YOUR_PROJECT_FOLDER>
## 5οΈβ£ Create a Dockerfile (if not already present)
# Use official Node.js image
FROM node:18
# Set the working directory
WORKDIR /app
# Copy package.json and install dependencies
COPY package*.json ./
RUN npm install
# Copy the rest of the app files
COPY . .
# Build the app
RUN npm run build
# Expose the port
EXPOSE 3000
# Start the application
CMD ["npm", "run", "start"]
## 6οΈβ£ Build and Push Docker Image to GCP
# Authenticate Docker with Google Cloud
gcloud auth configure-docker
# Set your project ID
export PROJECT_ID=$(gcloud config get-value project)
# Build the Docker image
docker build -t gcr.io/$PROJECT_ID/nest-app .
# Push the image to Google Container Registry
docker push gcr.io/$PROJECT_ID/nest-app
## 7οΈβ£ Deploy to Cloud Run
gcloud run deploy nest-app \
--image gcr.io/$PROJECT_ID/nest-app \
--platform managed \
--region us-central1 \
--allow-unauthenticated
-
Service name β Press
Enter
(default:nest-app
) -
Region β Choose
us-central1
(free tier) -
Allow unauthenticated β
y
(for public access)
## 8οΈβ£ Get the Live URL
Service [nest-app] revision [nest-app-xxxxx] has been deployed and is serving traffic at:
https://nest-app-xxxxxxxxxx-uc.a.run.app
π Your NestJS app is live! π
## 9οΈβ£ Optional: Connect a Custom Domain
- Go to Cloud Run > Your Service > Custom Domains
- Follow the setup process to map your domain.
β
Final Notes
- Cloud Run provides 2 million free requests per month.
- For databases, consider Firestore (free tier available).
- Want a free VM? Use Compute Engine (e2-micro instance).
π Happy coding! π₯
Top comments (0)