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 -y
to create apackage.json
file. - Install Express and the Redis client:
npm install express redis
- Create an
index.js
file in the project folder with the following content:
Configure the Fly.io application
- Run
fly init "your-app-name"
to initialize a new Fly.io application. - Choose the “Node.js (14.x)” builder, and accept the defaults for the remaining prompts.
- Open the
fly.toml
file that was generated and add the following environment variable under the[[services]]
section:
your-upstash-redis-url
with the Redis URL from your Upstash instance.
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.