A strongly-typed TypeScript boilerplate for Google Cloud Run functions supporting both HTTP and Pub/Sub event-driven triggers.
- ✅ HTTP handler for synchronous requests
- ✅ Pub/Sub event handler for asynchronous processing
- ✅ Fully typed with TypeScript (
strict: true) - ✅ Error handling and validation
- ✅ Local development support
- Node.js 18+
- Google Cloud SDK (
gcloudCLI) - A Google Cloud project
gcloud init
gcloud config set project PROJECT_IDnpm install
npm install --save-dev typescriptnpm run devThe function will be available at http://localhost:3000
Deploy an HTTP-triggered Cloud Run function:
gcloud functions deploy google-cloud-run-function-http \
--gen2 \
--trigger-http \
--runtime=nodejs18 \
--allow-unauthenticated \
--entry-point=google-cloud-run-function-httpgcloud pubsub topics create google-cloud-run-function-topicgcloud functions deploy google-cloud-run-function-event \
--gen2 \
--trigger-topic=google-cloud-run-function-topic \
--runtime=nodejs18 \
--entry-point=google-cloud-run-function-eventgcloud pubsub topics publish google-cloud-run-function-topic \
--message='{"key":"value"}'src/
├── index.ts # Main handlers (HTTP & Pub/Sub)
├── process.ts # Business logic
├── interfaces.ts # TypeScript interfaces
└── ...
dist/ # Compiled JavaScript (generated)
Send a POST request with JSON body:
curl -X POST http://localhost:3000 \
-H "Content-Type: application/json" \
-d '{"name": "John"}'Automatically processes messages from the subscribed topic.
- Google Cloud Functions Framework
- Google Cloud SDK Cheatsheet
- Cloud Run Documentation
- Pub/Sub Documentation
Set environment variables during deployment:
gcloud functions deploy my-function \
--gen2 \
--set-env-vars FOO=bar,BAZ=boo \
...