Node.js | Tigris Object Storage Documentation

Tigris with Node.js

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

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

Prerequisites

Install

Tigris SDK

npm install @tigrisdata/storage

AWS JS SDK

npm install @aws-sdk/client-s3

Configure credentials

Set your Tigris credentials as environment variables:

Tigris 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

AWS JS SDK

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

Tigris SDK

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

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

AWS JS SDK

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

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

import { get } from "@tigrisdata/storage";
const data = await get("hello.txt");
console.log(data.toString());

List objects

import { list } from "@tigrisdata/storage";
const objects = await list();
console.log(objects);

Delete an object

import { del } from "@tigrisdata/storage";
await del("hello.txt");

Upload an object with AWS JS SDK

import { PutObjectCommand } from "@aws-sdk/client-s3";
await s3.send(
  new PutObjectCommand({
    Bucket: "my-bucket",
    Key: "hello.txt",
    Body: "Hello, World!",
  }),
);

Download an object with AWS JS SDK

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 with AWS JS SDK

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

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