Skip to main content

Prerequisites

  • Astro project with SSR enabled (output: "server" or "hybrid")
  • A EvoCrawl API key — get one free

Install the SDK

npm install @mendable/evocrawl-js
Add your API key to .env:
EVOCRAWL_API_KEY=fc-YOUR-API-KEY

Search the web

Create src/pages/api/search.ts:
import type { APIRoute } from "astro";
import Evocrawl from "@mendable/evocrawl-js";

const evocrawl = new Evocrawl({
  apiKey: import.meta.env.EVOCRAWL_API_KEY,
});

export const POST: APIRoute = async ({ request }) => {
  const { query } = await request.json();
  const results = await evocrawl.search(query, { limit: 5 });
  return new Response(JSON.stringify(results), {
    headers: { "Content-Type": "application/json" },
  });
};
Or search at request time in a server-rendered page (src/pages/search.astro):
---
import Evocrawl from "@mendable/evocrawl-js";

const evocrawl = new Evocrawl({
  apiKey: import.meta.env.EVOCRAWL_API_KEY,
});

const query = Astro.url.searchParams.get("q");
let results = [];

if (query) {
  const searchData = await evocrawl.search(query, { limit: 5 });
  results = searchData.web || [];
}
---

<html>
  <body>
    <h1>Search Results</h1>
    {results.length > 0 ? (
      <ul>
        {results.map((r) => (
          <li><a href={r.url}>{r.title}</a></li>
        ))}
      </ul>
    ) : (
      <p>Pass ?q= to search the web</p>
    )}
  </body>
</html>

Scrape a page

Create src/pages/api/scrape.ts:
import type { APIRoute } from "astro";
import Evocrawl from "@mendable/evocrawl-js";

const evocrawl = new Evocrawl({
  apiKey: import.meta.env.EVOCRAWL_API_KEY,
});

export const POST: APIRoute = async ({ request }) => {
  const { url } = await request.json();
  const result = await evocrawl.scrape(url);
  return new Response(JSON.stringify(result), {
    headers: { "Content-Type": "application/json" },
  });
};
Or scrape at request time in a server-rendered page (src/pages/scrape.astro):
---
import Evocrawl from "@mendable/evocrawl-js";

const evocrawl = new Evocrawl({
  apiKey: import.meta.env.EVOCRAWL_API_KEY,
});

const target = Astro.url.searchParams.get("url");
let markdown = null;

if (target) {
  const result = await evocrawl.scrape(target);
  markdown = result.markdown;
}
---

<html>
  <body>
    <h1>Scraped Content</h1>
    {markdown ? <pre>{markdown}</pre> : <p>Pass ?url= to scrape a page</p>}
  </body>
</html>

Interact with a page

Create src/pages/api/interact.ts:
import type { APIRoute } from "astro";
import Evocrawl from "@mendable/evocrawl-js";

const evocrawl = new Evocrawl({
  apiKey: import.meta.env.EVOCRAWL_API_KEY,
});

export const POST: APIRoute = async () => {
  const result = await evocrawl.scrape("https://www.amazon.com", {
    formats: ["markdown"],
  });

  const scrapeId = result.metadata?.scrapeId;

  await evocrawl.interact(scrapeId, {
    prompt: "Search for iPhone 16 Pro Max",
  });

  const response = await evocrawl.interact(scrapeId, {
    prompt: "Click on the first result and tell me the price",
  });

  await evocrawl.stopInteraction(scrapeId);

  return new Response(JSON.stringify({ output: response.output }), {
    headers: { "Content-Type": "application/json" },
  });
};

Next steps

Scrape docs

All scrape options including formats, actions, and proxies

Search docs

Search the web and get full page content

Interact docs

Click, fill forms, and extract dynamic content

Node SDK reference

Full SDK reference with crawl, map, batch scrape, and more