# Node.js

There are two ways to use Tigris with Node.js:

* **[Tigris SDK](https://www.npmjs.com/package/@tigrisdata/storage)** — a type-safe SDK for TypeScript and JavaScript with a simple, high-level API. This is the recommended approach.
* **[AWS JavaScript SDK](/docs/sdks/s3/aws-js-sdk/.md)** — use the standard AWS SDK for JavaScript v3, just point it at Tigris. Useful if you have existing AWS S3 code to migrate.

Both are fully S3-compatible. We recommend the Tigris SDK for new projects.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

* Node.js 18+
* A Tigris account — create one at [storage.new](https://storage.new)
* An access key from [console.storage.dev/createaccesskey](https://console.storage.dev/createaccesskey)

## Install[​](#install "Direct link to Install")

* Tigris SDK
* AWS JS SDK

```
npm install @tigrisdata/storage
```

```
npm install @aws-sdk/client-s3
```

## Configure credentials[​](#configure-credentials "Direct link to Configure credentials")

Set your Tigris credentials as environment variables:

* Tigris SDK
* AWS JS SDK

```
export TIGRIS_STORAGE_ACCESS_KEY_ID="tid_your_access_key"

export TIGRIS_STORAGE_SECRET_ACCESS_KEY="tsec_your_secret_key"

export TIGRIS_STORAGE_BUCKET="my-bucket"
```

Or add them to a `.env` file in your project root:

```
TIGRIS_STORAGE_ACCESS_KEY_ID=tid_your_access_key

TIGRIS_STORAGE_SECRET_ACCESS_KEY=tsec_your_secret_key

TIGRIS_STORAGE_BUCKET=my-bucket
```

```
export AWS_ACCESS_KEY_ID="tid_your_access_key"

export AWS_SECRET_ACCESS_KEY="tsec_your_secret_key"

export AWS_ENDPOINT_URL="https://t3.storage.dev"

export AWS_REGION="auto"
```

## Create a client[​](#create-a-client "Direct link to Create a client")

* Tigris SDK
* AWS JS SDK

The Tigris SDK reads credentials from environment variables automatically — no client setup needed:

```
import { list, put, get } from "@tigrisdata/storage";
```

```
import { S3Client } from "@aws-sdk/client-s3";



const s3 = new S3Client({

  region: "auto",

  endpoint: "https://t3.storage.dev",

});
```

If you set `AWS_ENDPOINT_URL` in your environment, you can omit the `endpoint` option.

## Basic operations[​](#basic-operations "Direct link to Basic operations")

* Tigris SDK
* AWS JS SDK

### Upload an object[​](#upload-an-object "Direct link to Upload an object")

```
import { put } from "@tigrisdata/storage";



await put("hello.txt", "Hello, World!");



// Upload a file from disk

import { readFileSync } from "fs";

await put("data.csv", readFileSync("data.csv"));
```

### Download an object[​](#download-an-object "Direct link to Download an object")

```
import { get } from "@tigrisdata/storage";



const data = await get("hello.txt");

console.log(data.toString());
```

### List objects[​](#list-objects "Direct link to List objects")

```
import { list } from "@tigrisdata/storage";



const objects = await list();

console.log(objects);
```

### Delete an object[​](#delete-an-object "Direct link to Delete an object")

```
import { del } from "@tigrisdata/storage";



await del("hello.txt");
```

### Upload an object[​](#upload-an-object-1 "Direct link to Upload an object")

```
import { PutObjectCommand } from "@aws-sdk/client-s3";



await s3.send(

  new PutObjectCommand({

    Bucket: "my-bucket",

    Key: "hello.txt",

    Body: "Hello, World!",

  }),

);
```

### Download an object[​](#download-an-object-1 "Direct link to Download an object")

```
import { GetObjectCommand } from "@aws-sdk/client-s3";



const result = await s3.send(

  new GetObjectCommand({

    Bucket: "my-bucket",

    Key: "hello.txt",

  }),

);

const body = await result.Body.transformToString();

console.log(body);
```

### List objects[​](#list-objects-1 "Direct link to List objects")

```
import { ListObjectsV2Command } from "@aws-sdk/client-s3";



const result = await s3.send(new ListObjectsV2Command({ Bucket: "my-bucket" }));

for (const obj of result.Contents ?? []) {

  console.log(`  ${obj.Key}  (${obj.Size} bytes)`);

}
```

### Generate a presigned URL[​](#generate-a-presigned-url "Direct link to Generate a presigned URL")

```
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";

import { GetObjectCommand } from "@aws-sdk/client-s3";



const url = await getSignedUrl(

  s3,

  new GetObjectCommand({ Bucket: "my-bucket", Key: "hello.txt" }),

  { expiresIn: 3600 },

);

console.log(url);
```

## Next steps[​](#next-steps "Direct link to Next steps")

* [Example Next.js app](https://github.com/tigrisdata-community/storage-sdk-examples) — a Next.js app that uploads and manages files with the Tigris SDK, ready to deploy to Vercel
* [Tigris SDK reference](/docs/sdks/tigris/.md) — full SDK documentation including client uploads, multipart uploads, and more
* [AWS JS SDK reference](/docs/sdks/s3/aws-js-sdk/.md) — advanced usage with presigned URLs, metadata queries, and conditional operations
