Node.js cloud functions
CommonJS entry handles event and context; compose database, storage, and third-party services via NPM.
Serverless functions for events and schedules; CloudRun containers for full web services, any language, and long connections. Both connect to CloudBase resources.
Node.js · HTTP · LATEST
Node.js · timer · v3
Container · WebSocket · 002
Request ID, revision, and stdout follow execution so you can see what happened in which function or container.
SDK · HTTP · Timer
Node.js Function · CloudRun
Database · storage · external APIs
Pick compute by workload — you don't need one runtime for every backend concern.
CommonJS entry handles event and context; compose database, storage, and third-party services via NPM.
Trigger via SDK, HTTP, or seven-field Cron — same runtime for requests and background jobs.
Configure HTTP access, custom paths, and domains; return JSON or custom integration responses.
Publish immutable versions; shift traffic between LATEST and stable revisions to validate safely.
Deploy containerized CloudRun when you need any language, full frameworks, long connections, or multi-process apps.
Trace stdout, invocations, latency, HTTP errors, and resource usage by request and revision.
Serverless isn't about hiding code — it's about moving focus from server lifecycles back to requests, revisions, and business outcomes.Product design principle
Functions handle short event-driven work; CloudRun handles full frameworks, streaming, and long-lived connections.
Compare compute optionsExamples focus on documented Node.js functions, timer triggers, and Docker containers in this repo.
index.js exports an async main; event carries trigger data, context provides request and execution context.
// index.js
exports.main = async (event, context) => {
const { sku, quantity = 1 } = event
const order = await createOrder({
sku,
quantity,
requestId: context.requestId
})
return {
ok: true,
orderId: order.id
}
}Configure reports, cleanup, or sync as timer triggers — no dedicated scheduler process.
{
"triggers": [
{
"name": "daily-report",
"type": "timer",
"config": "0 0 2 * * * *"
}
]
}When you need any language version, a full web framework, or long connections, define deps and startup in a container.
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
ENV PORT=8080
EXPOSE 8080
CMD ["node", "server.js"]Events, APIs, background jobs, and full services can run close to CloudBase data and identity.
Data processing, notifications, and resource callbacks.
HTTP endpoints, webhooks, and third-party integrations.
Full frameworks, streaming responses, and long connections.
Start with your first cloud function, or bring existing container services to CloudRun.