Easily upload files from a Node.js server to Restash. This guide shows you how to set up server-side uploads using our lightweight SDK.

You can only upload files up to 4MB on the server. If you want to upload files larger than 4MB, you can use the client side SDK to upload files directly from the browser.

Prerequisites

To follow this guide, you will need to:

Install and initialize Restash

1

Install

Install Restash Node using your preferred package manager.

npm i @restash/node
2

Initialize Restash

Initialize Restash with your private API key.

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

export const restash = new Restash("sk_123456789");
3

Use Restash anywhere in your server code

You can now import Restash and use it to upload files.

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

Uploading your first file on the server

In this example, we will upload a file inside a Next.js API route.

api/upload/route.ts
import { NextResponse, NextRequest } from "next/server";
import { restash } from "@/lib/restash";

export const POST = async (req: NextRequest) => {
  const formData = await req.formData();
  const file = formData.get("file") as File;

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

  // store the upload in your db or do something else with it
  console.log(upload.url);

  return NextResponse.json(upload);
};

Next steps

Check out the full Node.js SDK for more information on how to use the SDK.