Skip to main content
The Upstash Redis SDK works seamlessly in Node.js environments, including serverless functions, AWS Lambda, and traditional Node.js applications.

Installation

Quick Start

1

Import the SDK

The default export is optimized for Node.js:
You can also use the explicit Node.js import:
2

Create a Redis instance

Use fromEnv() to automatically load credentials from environment variables:
This will read from:
  • UPSTASH_REDIS_REST_URL or KV_REST_API_URL
  • UPSTASH_REDIS_REST_TOKEN or KV_REST_API_TOKEN
The fallback variables (KV_REST_API_URL and KV_REST_API_TOKEN) provide compatibility with Vercel KV and other platforms.
3

Use Redis commands

Configuration Options

The Node.js SDK supports several configuration options:

Connection Pooling with Agent

For optimal performance in Node.js applications with multiple sequential requests, use an HTTP(S) agent:
The agent option is Node.js specific and not supported in edge runtimes like Vercel Edge Functions or Cloudflare Workers.

Using fromEnv() with Options

You can combine fromEnv() with additional configuration:

Example Application

Platform Detection

The SDK automatically detects the runtime environment and sets appropriate telemetry:
  • Node.js: Reports as node@<version> (e.g., node@18.17.0)
  • Edge Runtime: Reports as edge-light when running in Vercel Edge Functions
  • Platform: Detects Vercel, AWS, or Upstash Console environments

Environment Variables

When using Redis.fromEnv(), the SDK looks for these environment variables via process.env:
If process.env is not available (e.g., in Cloudflare Workers), use the platform-specific import instead: @upstash/redis/cloudflare