Home

Installing Upstash.js

npm i upstash.js
yarn add upstash.js

Initializing Upstash.js

If you have the environment variables UPSTASH_URL and UPSTASH_TOKEN , you can initialize this library like so:

import Upstash from "upstash.js"

const upstash = new Upstash()

Otherwise, you can set these manually

const upstash = new Upstash({
    url: "Your Upstash URL",
    token: "Your Upstash REST Token"
})

General Usage

The return type for all methods on the Upstash objects is a tuple, where one of the two values is always undefined. If there was some sort of error, the return type is [undefined, string], where the string is the description of the error. Otherwise, the return type if [result, undefined. You can destructure the return value like so:

import Upstash from "upstash.js"

const upstash = new Upstash();

//here we destructure the return type into two variables result and error
const [result, error] = await upstash.get("keyname")

//we can check if there is an error
if (error) {
    //handle error
}

//now we know that there was no error, we can work with the result
console.log(result)

Last updated