Installation

npm i @restash/node

Initialize Restash

lib/restash.ts
import { Restash } from "@restash/node";

export const restash = new Restash(process.env.RESTASH_SECRET_KEY);
The Restash class accepts a single parameter, which is your private API key. You can create an API key here.

Upload a file

import { restash } from "@/lib/restash";

const file = new File(["test"], "test.txt", {
  type: "text/plain",
});

const result = await restash.files.upload(file);

// do something with the uploaded file
const { url } = result;
The upload method accepts the following parameters:
file
File | Blob
required
The file or blob to upload.
options
UploadOptions object
An object with the following optional properties:
A successful upload will respond with the following:
data
UploadFileResponseSuccess object
The information about the uploaded file.

Retrieve a file

import { restash } from "@/lib/restash";

// can be a file id or key
const file = await restash.files.retrieve({ id: "file-id" });
The retrieve method accepts the following parameters:
options
RetrieveFileOptions object
An object with the following properties, either id or key is required:
A successful retrieval will respond with the following:
data
RetrieveFileResponseSuccess object
The information about the retrieved file.

Delete a file

import { restash } from "@/lib/restash";

const result = await restash.files.delete("file-id");
The delete method accepts the following parameters:
options
DeleteFileOptions object
An object with the following properties, either id or key is required:
A successful deletion will respond with the following:
data
DeleteFileResponseSuccess object
A confirmation of the deletion.

Additional resources