How to create and deploy a Node.js app

Building a Node.js application is only the first part of the software development lifecycle; making it accessible, performant, and resilient in a live environment is where application delivery matters. Deploying modern web applications involves selecting an architecture that matches your traffic profile, lifecycle stage, and resource budget.

Whether you are launching an AI-assisted full-stack prototype or deploying a production-grade backend service, modern cloud environments offer both automated and containerized pathways. This guide covers the core concepts of Node.js web architecture, explores key deployment considerations, and walks step-by-step through how to create and deploy a Node.js app on managed infrastructure using free-tier allowances.

What is the Node.js runtime?

Node.js is an open-source, cross-platform JavaScript runtime environment built on Chrome V8 JavaScript engine. It enables JavaScript to run server-side outside the web browser, allowing engineers to write unified full-stack codebases using a single programming language.

Unlike traditional multithreaded web servers that spawn an isolated operating system thread for every concurrent connection, Node.js operates on an event-driven, single-threaded, non-blocking I/O model. This architecture makes Node.js lightweight and efficient for handling thousands of concurrent connections—such as RESTful APIs, real-time messaging, streaming services, and AI agent orchestrators.

Traditional Node.js deployment versus serverless container platforms

When preparing to deploy a Node.js backend, selecting the right compute environment directly impacts maintenance overhead, scaling speed, and cost efficiency.

Feature

Virtual machines (IaaS / VPS)

PaaS / buildpack hosting

Modern serverless containers

Infrastructure management

Manual OS patching, firewall management, and runtime updates

Fully managed platform layer with vendor runtime locks

Fully managed infrastructure; zero OS management

Scaling mechanism

Metric-based VM autoscaling (takes minutes to spin up instances)

Autoscaling by instance count or worker limits

Request-driven instantaneous autoscaling, including scale-to-zero

Packaging format

Raw source files, systemd services, or PM2 process managers

Git push repository integration with automated buildpacks.

Standard OCI / Docker container images

Idle cost profile

Billed 24/7 regardless of incoming HTTP traffic

Often requires minimum base instance pricing.

Billed strictly per-second during active request processing

Portability

High portability, but high environment drift risk

Low portability; locked to platform conventions

High portability; runs identical container across any environment

Feature

Virtual machines (IaaS / VPS)

PaaS / buildpack hosting

Modern serverless containers

Infrastructure management

Manual OS patching, firewall management, and runtime updates

Fully managed platform layer with vendor runtime locks

Fully managed infrastructure; zero OS management

Scaling mechanism

Metric-based VM autoscaling (takes minutes to spin up instances)

Autoscaling by instance count or worker limits

Request-driven instantaneous autoscaling, including scale-to-zero

Packaging format

Raw source files, systemd services, or PM2 process managers

Git push repository integration with automated buildpacks.

Standard OCI / Docker container images

Idle cost profile

Billed 24/7 regardless of incoming HTTP traffic

Often requires minimum base instance pricing.

Billed strictly per-second during active request processing

Portability

High portability, but high environment drift risk

Low portability; locked to platform conventions

High portability; runs identical container across any environment

Key considerations when creating a Node.js app

Developing a production-ready Node.js application requires addressing architectural patterns that prevent bottlenecks and ensure uptime:

  • Stateless application state: Modern serverless platforms dynamically spin container instances up and down in response to incoming traffic. Avoid saving user session state, uploaded media files, or background queues in local container memory or local disk paths, as files written to temporary container disks vanish on redeployment or scale-down. Use dedicated managed services such as Cloud Firestore, Cloud SQL for PostgreSQL, or Cloud Storage for persistent state.
  • Environment variables and secret isolation: Hardcoding API keys, database credentials, or secret keys into source control creates critical security vulnerabilities. Always isolate runtime configurations into environment variables (process.env) and inject them securely at the container runtime level.
  • Port binding and health probes: Serverless container environments route HTTP traffic by injecting a default target port such as the PORT environment variable (typically port 8080). Your Node.js server must dynamically listen on process.env.PORT || 8080 to pass health and readiness checks.
  • Graceful shutdown & signal trapping: Node.js applications should intercept SIGTERM and SIGINT operating system signals. When an infrastructure autoscaler initiates a scale-down, handling these signals ensures existing HTTP requests finish processing before database connections close and the container terminates.

How to create and deploy a Node.js app

You can create and deploy a Node.js application using two primary workflows: Rapid AI-Assisted Prototyping (no local setup required) or Standard Container-Based Deployment (for existing codebases).

Pathway A: Rapid prototyping such as AI Studio build mode and starter tier (free provisioning)

For rapid prototyping and AI applications, Google AI Studio build mode allows developers to describe full-stack Node.js architectures in natural language and deploy them to Cloud Run without local command-line tools or mandatory billing setups.

Step 1: Initialize the application in build mode

  1. Navigate to Google AI Studio and switch to build mode.
  2. Enter your application prompt describing your required business logic and frontend interface (for example, "Build an inventory tracking dashboard with a Node.js backend and persistent task management").
  3. The integrated agent will generate the application files, configure your server routes, install relevant npm dependencies, and launch an interactive preview.

Step 2: Configure built-in data and authentication

  • For persistent storage: When your prompt requires data storage, enable Cloud Firestore or Cloud SQL for PostgreSQL (Developer Edition). AI Studio automatically drafts your schema, models, and client connection files.
  • For User Identity: Toggle Firebase Authentication to enable preconfigured Google Sign-In flows without setting up separate OAuth redirect handlers manually.

Step 3: Publish to managed Cloud Run

  1. Click Publish > Get Started > Publish App in the upper interface.
  2. Select your preferred deployment region.
  3. Provide a Custom <user-defined>.ai.studio URL for your application and publish.
  4. The platform packages your container, provisions the underlying compute, and yields a live <user-defined>.ai.studio HTTPS production URL in seconds.

Pathway B: Deploying a custom Node.js application such as Docker and Cloud Run

For pre-existing codebases and custom microservices, package your Node.js application into an OCI-compliant container and deploy directly to Cloud Run.

Step 1: Structure the Node.js server code

Create a minimal HTTP server using Express, Fastify, or standard Node.js libraries (index.js):

  • JavaScript
Loading...

 Note: Cloud Run injects the PORT environment variable automatically at runtime. The fallback || 8080 in the code above is primarily included to facilitate easy local testing on your machine before deployment.

Step 2: Create a secure, multi-stage Dockerfile

Package your application using a multi-stage build to ensure a minimal, secure production image.

Best practice: Create a .dockerignore file in your root directory and add node_modules and .env to it. This ensures local development files are not accidentally bundled into your container image, keeping it clean and secure.

Create a file named Dockerfile in your root directory:

  • Dockerfile
Loading...

Step 3: Deploy to Cloud Run

Execute the deployment using the Google Cloud CLI from your local root folder. You can also optionally create a Custom URL of the format <user-defined>.cloud.run for your application:

  • Bash
Loading...

To map a custom domain afterward, use:

  • Bash
Loading...

Free-tier and starter tier pricing mechanics

Understanding how free allocations work ensures you can prototype and scale your Node.js application predictably:

Tier type

Compute & resource allowances

Requirements / limits

Google Cloud starter tier (Prototyping)

• Cloud Run: Up to two active web applications

• Cloud Firestore: 1 GiB storage, 50k reads/day, 40k writes/day

• Cloud SQL: PostgreSQL Developer edition (scale-to-zero)

• Firebase Auth: Google sign-in included

• Valid Google account

• No credit card or billing account required

• Single deployment region lock

Standard Google Cloud free tier (standard account)

• Cloud Run: Two million requests/month, 180,000 vCPU-seconds/month, 360,000 GiB-seconds/month, 1 GB North America network egress/month

• Access to $300 welcome Credit for the first 90 days



• Linked Cloud Billing account

• Full platform API access across all regions

Tier type

Compute & resource allowances

Requirements / limits

Google Cloud starter tier (Prototyping)

• Cloud Run: Up to two active web applications

• Cloud Firestore: 1 GiB storage, 50k reads/day, 40k writes/day

• Cloud SQL: PostgreSQL Developer edition (scale-to-zero)

• Firebase Auth: Google sign-in included

• Valid Google account

• No credit card or billing account required

• Single deployment region lock

Standard Google Cloud free tier (standard account)

• Cloud Run: Two million requests/month, 180,000 vCPU-seconds/month, 360,000 GiB-seconds/month, 1 GB North America network egress/month

• Access to $300 welcome Credit for the first 90 days



• Linked Cloud Billing account

• Full platform API access across all regions

Solve your business challenges with Google Cloud

New customers get $300 in free credits to spend on Google Cloud.
Talk to a Google Cloud sales specialist to discuss your unique challenge in more detail.

Best practices for running Node.js in serverless environments

  1. Optimize cold starts with lean dependencies: Remove unused development packages (npm prune --production) and bundle server code using modern module tree-shakers (such as esbuild or tsup) to decrease image sizes and accelerate container initialization.
  2. Configure instance maximums: When moving from a sandbox to a live production project, specify a concurrency threshold and set --max-instances (for example, --max-instances 5) to ensure unexpected traffic spikes do not exceed target operating budgets.
  3. Persist logs structurally: Stream logs to stdout and stderr using structured JSON format. Managed logging systems automatically parse JSON objects, allowing you to filter by HTTP status codes, severity levels, and execution latency.
  4. Use native health checks: Implement clear HTTP endpoint probes (for example, /healthz) that verify downstream database connectivity before signaling readiness to incoming routing proxies.

Take the next step

Start building on Google Cloud with $300 in free credits and more than twenty always free products.

Google Cloud