npm
installed on your local machine to create the demo application.UPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
environment variables with the values for your Upstash database.
example-koyeb-upstash
.UPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
buttons to copy their respective values to your clipboard. Paste the copied values to a safe location so that you can reference them later when testing and deploying your application.
Alternatively, you can click on the @upstash/redis
tab to view a code snippet:
@upstash/redis
package to connect to the database.
package.json
file for the new project using the default settings:
@upstash/redis
package so that you can connect to your Redis database from within the application and the express
package so that we can build a basic web application:
index.js
with the following contents:
@upstash/redis/with-fetch
instead of @upstash/redis
. Node.js versions prior to 18 did not natively support fetch
API, so you need to change the import path in order to access that functionality.
This above code will introduce a simple counter
key to your Redis database. It will use this key to store the number of times the page has been accessed and display that value on the page.
package.json
file to define the scripts used to run the application. The dev
script runs the application in debug mode while the start
script starts the application normally:
127.0.0.1:3000
to see your application. It should show the counter and number of visits you’ve made: “Counter: 0”. The number should increase by one every time you refresh the page.
Press CTRL-c to stop the application when you are finished.
<YOUR_GITHUB_USERNAME>
and <YOUR_REPOSITORY_NAME>
with your own information:
upstash-service
.UPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
. Populate them with the values you copied for your Upstash Redis database.upstash-demo
..koyeb.app
.
<YOUR_GITHUB_USERNAME>/<YOUR_REPOSITORY_NAME>
with your GitHub username and repository name and replace <YOUR_UPSTASH_REDIS_REST_URL>
and <YOUR_UPSTASH_REDIS_REST_TOKEN>
with the values copied from your Upstash Redis page.
.dockerignore
to the project’s root directory. Paste the following contents to limit the files copied to the Docker image:
Dockerfile
in your project root directory and copy the content below:
UPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
environment variables to the values you copied from the Upstash console when you deploy the container in the Koyeb control panel.
To build and push the Docker image to a registry and deploy it on Koyeb, refer to the Deploy an app from a Docker image documentation.
A Koyeb App and Service will be created. Your Docker image will be pulled and deployed to Koyeb. Once the deployment has finished, you will be able to access your application running on Koyeb by clicking the URL ending with .koyeb.app
.
koyeb app delete example-koyeb-upstash
.