Skip to main content
The Geekflare SDK must only run server-side — your API key must never be exposed to the browser. Next.js makes this straightforward with Route Handlers, Server Actions, and Server Components.

Prerequisites

  • Next.js 14+ with the App Router
  • Node.js 18+
  • A Geekflare API key — get one free

Installation

Set your API key

Add your API key to .env.local:
.env.local
.env.local is gitignored by default in Next.js. Never prefix this variable with NEXT_PUBLIC_ — that would expose it to the browser.

Shared client

Create a single client instance to reuse across your app:
lib/geekflare.ts

Web Scraping

Route Handler

Accepts a POST request from your client-side code and returns scraped content.
app/api/scrape/route.ts

Server Action

Use directly from Client Components without a round-trip to a route:
app/actions.ts

Server Component

Fetch and render scraped content directly in a Server Component:
app/scrape/page.tsx

Route Handler

app/api/search/route.ts

Server Action

app/actions.ts

Server Component

app/search/page.tsx

Screenshot

Route Handler

app/api/screenshot/route.ts

Server Component

Render the screenshot directly in a page using next/image:
app/preview/page.tsx

Error handling

Handle errors consistently across Route Handlers and Server Actions.

Common error codes

See Rate Limit Exceeded and Credit Exhausted for strategies to handle these gracefully.

Route Handler pattern

Server Action pattern

Consume it safely in a Client Component:

Next steps