Skip to main content

Prerequisites

Setup

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

Search the web

import Fastify from "fastify";
import Firecrawl from "@mendable/firecrawl-js";

const fastify = Fastify({ logger: true });
const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });

fastify.post("/search", async (request) => {
  const { query } = request.body;
  return firecrawl.search(query, { limit: 5 });
});

fastify.listen({ port: 3000 });

Scrape a page

fastify.post("/scrape", async (request) => {
  const { url } = request.body;
  return firecrawl.scrape(url);
});

Interact with a page

Use interact to control a live browser session — click buttons, fill forms, and extract dynamic content.
fastify.post("/interact", async (request) => {
  const { url } = request.body;

  const result = await firecrawl.scrape(url, { 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 };
});

As a Fastify plugin

Encapsulate the client in a plugin for reuse across routes:
import fp from "fastify-plugin";
import Firecrawl from "@mendable/firecrawl-js";

export default fp(async function firecrawlPlugin(fastify) {
  const client = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });
  fastify.decorate("firecrawl", client);
});
Register the plugin, then use fastify.firecrawl in any route:
fastify.register(firecrawlPlugin);

fastify.post("/search", async function (request) {
  const { query } = request.body;
  return this.firecrawl.search(query, { limit: 5 });
});

Test it

curl -X POST http://localhost:3000/search \
  -H "Content-Type: application/json" \
  -d '{"query": "firecrawl web scraping"}'

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