Next.js Adapter

How to set up API routes for Filenest in a Next.js app.

Setup

1. Install dependencies

npm
yarn
pnpm
bun
1npm install @filenest/core @filenest/adapter-nextjs

2. Create a route handler

The Next.js adapter only works with route handlers inside the app directory.

Create the following file structure:

app └── api └── media └── [action] └── route.ts

Your folder structure may differ depending on your project setup. Just make sure there is a main folder for Filenest routes (e.g. media) and a catch-all route (e.g. [action]).

Then just initialize the adapter inside the route.ts file and pass it a provider.

app/api/media/[action]/route.ts
import { initNextjsAdapter } from "@filenest/adapter-nextjs" import { Cloudinary } from "@filenest/provider-cloudinary" const provider = new Cloudinary({...}) export const { POST } = initNextjsAdapter({ provider })

Now you're all set to build your UI. Check out the minimal setup to get started.