Fly.io has a native integration with Upstash where the databases are hosted in
Fly. You can still access a Redis from Fly to Upstash but for the best
latency, we recommend creating Redis (Upstash) inside Fly platform. Check
here for details.
Redis Setup
Create a Redis database using Fly CLISet up the Node.js application
- Create a new folder for your project and navigate to it in the terminal.
- Run
npm init -yto create apackage.jsonfile. - Install Express and the Redis client:
npm install express redis - Create an
index.jsfile in the project folder with the following content:
Configure the Fly.io application
- Run
fly launchto initialize a new Fly.io application, and accept the defaults for the prompts. - Since the Redis URL contains your database password, store it as a secret
instead of putting it in
fly.toml:
your-upstash-redis-url with the Redis URL from your Upstash instance.
The secret is made available to your application as the REDIS_URL environment
variable.
Deploy the application to Fly.io
- Run fly deploy to build and deploy your application.
- After the deployment is complete, run fly status to check if the application is running.
- Visit the URL provided in the output (e.g., https://your-app-name.fly.dev) to test your application.
Conclusion
You have successfully deployed a Node.js application on Fly.io that uses an Upstash Redis instance as its data store. You can now build and scale your application as needed, leveraging the benefits of both Fly.io and Upstash.Local Development
Your database is only reachable over your Fly organization’s private IPv6 network, so theredis://...upstash.io URL does not work from your local machine. For local development, Fly CLI can open a secure tunnel to the database.
Explore your data with redis-cli
16379 to your database and opens an interactive redis-cli session, so you can inspect keys and run commands directly.
Run your application against the tunnel
To use the database from a locally running application, open a plain proxy instead:localhost:16379 using the password from your Redis URL:
REDIS_URL from the environment, no code changes are needed.
The tunnel is meant for development and testing, not production. For a fully
local setup, you can also run a local Redis server instead.