Example: Deploy a Node.js application¶
This example demonstrates a complete how-to guide written in Google documentation style.
Deploy a Node.js application to Cloud Run¶
Deploy your Node.js application to Cloud Run, Google Cloud's fully managed serverless platform. After completing these steps, your application will be publicly accessible via HTTPS.
Before you begin¶
- Install the Google Cloud CLI
- Create a Google Cloud project
- Enable the Cloud Run API
- Install Docker (version 20.10 or later)
Prepare your application¶
-
Create a
Dockerfilein your project root: -
Add a
.dockerignorefile to exclude unnecessary files: -
Ensure your application listens on the port specified by the
PORTenvironment variable:Cloud Run sets theconst PORT = process.env.PORT || 8080; app.listen(PORT, () => { console.log(`Server listening on port ${PORT}`); });PORTenvironment variable automatically.
Build and deploy the application¶
-
Authenticate with Google Cloud:
A browser window opens. Complete the sign-in process with your Google account. -
Set your project ID:
ReplacePROJECT_IDwith your Google Cloud project ID. -
Build and deploy your application in one command:
This command:
- Builds a container image from your application
- Pushes the image to Container Registry
- Deploys the image to Cloud Run in the us-central1 region
- Makes the service publicly accessible
The deployment takes 2-5 minutes. When complete, the command displays your service URL:
Service [myapp] revision [myapp-00001] has been deployed and is serving 100 percent of traffic.
Service URL: https://myapp-abc123-uc.a.run.app
- Test your deployed application:
Replace
SERVICE_URLwith the URL from the previous step.
Update your application¶
To deploy a new version:
-
Make changes to your application code.
-
Deploy the updated application:
Cloud Run creates a new revision and gradually shifts traffic to it.
Configure environment variables¶
To add environment variables to your service:
Caution: Don't store sensitive values directly in environment variables. Use Secret Manager for sensitive data.
Monitor your application¶
-
View your service logs:
-
Open the Cloud Run console to view metrics:
Open the displayed URL in your browser and append/logsto view detailed metrics.
What's next¶
- Set up a custom domain
- Configure continuous deployment
- Implement authentication
- Optimize container startup time
Why This Example Follows Google Style¶
Title and Structure¶
- ✅ Uses sentence case: "Deploy a Node.js application to Cloud Run"
- ✅ Task-oriented and specific
- ✅ Clear introduction stating purpose and outcome
- ✅ Proper heading hierarchy (H1 → H2)
Voice and Tone¶
- ✅ Uses second person: "your application", "you complete"
- ✅ Active voice: "Cloud Run sets the PORT variable" (not "The PORT variable is set")
- ✅ Present tense: "The command displays" (not "will display")
- ✅ Conversational: Uses contractions like "don't"
Instructions¶
- ✅ Numbered steps with one action each
- ✅ Imperative mood: "Create a Dockerfile", "Deploy your application"
- ✅ Shows expected results after commands
- ✅ Includes verification steps
Code and Formatting¶
- ✅ Complete, runnable code examples
- ✅ Language specified for code blocks (dockerfile, javascript, bash)
- ✅ Comments explain non-obvious parts
- ✅ Placeholders clearly marked: PROJECT_ID, SERVICE_URL
- ✅ Inline code uses backticks:
PORT,.dockerignore - ✅ UI elements would be bolded (none in this example)
Accessibility¶
- ✅ Descriptive link text: [Google Cloud CLI] not [here]
- ✅ Proper alt text for images (none in this example)
- ✅ Inclusive language (they/their if pronouns were used)
- ✅ No skipped heading levels
Additional Elements¶
- ✅ Prerequisites listed clearly
- ✅ Caution callout for security concern
- ✅ "What's next" section with related resources
- ✅ Expected command output shown
- ✅ Error handling considerations
Word Choice¶
- ✅ "Enter" for commands (not "type in")
- ✅ "Complete the sign-in process" (not "login")
- ✅ No "please", "simply", or "just"
- ✅ No Latin abbreviations (would use "for example" not "e.g.")