> For the complete documentation index, see [llms.txt](https://julianbuse007.gitbook.io/upstash-js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://julianbuse007.gitbook.io/upstash-js/master.md).

# Home

## Installing Upstash.js

```bash
npm i upstash.js
```

```bash
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:

```typescript
import Upstash from "upstash.js"

const upstash = new Upstash()
```

Otherwise, you can set these manually

```typescript
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:

```typescript
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)
```
