Skip to main content

Prerequisites

Install the SDK

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

Search the web

Create server/api/search.post.ts:
import Firecrawl from "@mendable/firecrawl-js";

const firecrawl = new Firecrawl({
  apiKey: process.env.FIRECRAWL_API_KEY,
});

export default defineEventHandler(async (event) => {
  const { query } = await readBody(event);
  const results = await firecrawl.search(query, { limit: 5 });
  return results;
});
Call it from a Vue component:
<script setup>
const query = ref("");
const { data, execute } = useFetch("/api/search", {
  method: "POST",
  body: { query },
  immediate: false,
});
</script>

<template>
  <div>
    <input v-model="query" placeholder="Search the web..." />
    <button @click="execute()">Search</button>
    <ul v-if="data?.web">
      <li v-for="result in data.web" :key="result.url">
        <a :href="result.url">{{ result.title }}</a>
      </li>
    </ul>
  </div>
</template>

Scrape a page

Create server/api/scrape.post.ts:
import Firecrawl from "@mendable/firecrawl-js";

const firecrawl = new Firecrawl({
  apiKey: process.env.FIRECRAWL_API_KEY,
});

export default defineEventHandler(async (event) => {
  const { url } = await readBody(event);
  const result = await firecrawl.scrape(url);
  return result;
});
Call it from a Vue component:
<script setup>
const url = ref("https://example.com");
const { data, execute } = useFetch("/api/scrape", {
  method: "POST",
  body: { url },
  immediate: false,
});
</script>

<template>
  <div>
    <input v-model="url" placeholder="Enter URL" />
    <button @click="execute()">Scrape</button>
    <pre v-if="data">{{ data.markdown }}</pre>
  </div>
</template>

Interact with a page

Create server/api/interact.post.ts:
import Firecrawl from "@mendable/firecrawl-js";

const firecrawl = new Firecrawl({
  apiKey: process.env.FIRECRAWL_API_KEY,
});

export default defineEventHandler(async (event) => {
  const result = await firecrawl.scrape("https://www.amazon.com", {
    formats: ["markdown"],
  });

  const scrapeId = result.metadata?.scrapeId;

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

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

  await firecrawl.stopInteraction(scrapeId);

  return { output: response.output };
});

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