Tutorials
Nuxt.js with Redis
This tutorial shows how to use Upstash inside your NuxtJS application.
This tutorial uses Redis as state store for a Nuxt.js application. We simply increment a counter that pulls the data from Redis.
1
Create Nuxt.js Project
Run this in terminal
2
Set up environment variables
Copy the .env.example
file in this directory to .env
REDIS_URL
: Copy the url in the database page of the Upstash console
This example uses ioredis, you can copy the connection string from the Node tab in the console.
3
Server Middleware
We will write a Nuxt middleware which increments a counter in Redis and returns its new value.
title="api/count.js"
Now we will configure the middleware in nuxt.config.js
title="nuxt.config.js"
4
Run
Go to http://localhost:3000/
Notes:
- For best performance the application should run in the same region with the Redis database’s region.