Skip to main content

Node.js Deployment

Deploy Genkit applications to any Node.js platform using Express integration. Works with Vercel, Fly.io, AWS, Render, Railway, and more.

Overview

Genkit provides first-class Express.js integration through the @genkit-ai/express plugin:
  • Framework agnostic - Works with any Node.js HTTP server
  • Built-in streaming - Server-Sent Events (SSE) support
  • Authentication - Context providers for auth
  • Flexible deployment - Deploy anywhere Node.js runs

Installation

Basic Setup

1. Create Express Server

src/index.ts

2. Test Locally

Express Handler Options

Basic Usage

With Authentication

With Streaming

Streaming is enabled automatically when:
  1. Request has Accept: text/event-stream header, OR
  2. Request has ?stream=true query parameter
Response format:

Flow Server

Use startFlowServer to automatically expose all flows:
This exposes:
  • POST /jokeFlow
  • POST /summarizeFlow

With Authentication

Custom Paths

Advanced Patterns

Direct Flow Invocation

Raw Streaming

Multiple Flows

CORS Configuration

Deployment Platforms

Vercel

vercel.json

Fly.io

fly.toml

Render

render.yaml

Railway

AWS Elastic Beanstalk

Heroku

Procfile

Complete Example

See the full Express integration example:
Source: js/testapps/express/src/index.ts This example demonstrates:
  • Flow via expressHandler with auth
  • Flow without auth
  • Direct flow invocation
  • Raw streaming
  • Context providers

Testing the Example

Durable Streaming (Beta)

Persist stream state to handle client reconnections:
Clients receive a stream ID in the X-Genkit-Stream-Id header:

Production Best Practices

1. Error Handling

2. Request Validation

3. Rate Limiting

4. Timeout Handling

5. Health Checks

Monitoring

Express Middleware

Structured Logging

Troubleshooting

Request Body Undefined

Problem: request.body is undefined. Solution: Add JSON middleware:

CORS Errors

Problem: Browser blocks requests. Solution: Enable CORS:

Streaming Not Working

Problem: Streaming doesn’t start. Solution: Add query parameter or header:

Next Steps

Express Plugin

Full Express plugin documentation

Cloud Run

Deploy to Google Cloud Run