Skip to content

SDKs

Node

Copy page

Use the Firecrawl SDK from JavaScript with DarkCrawl, and what to know about retries and stored copies.

Works with Node.js

Install the Firecrawl SDK for JavaScript, then point it at DarkCrawl. The sample uses the firecrawl package. DarkCrawl’s compatibility tests run @mendable/firecrawl-js 4.51.0.

Node
// npm install firecrawl
import { Firecrawl } from 'firecrawl';

const firecrawl = new Firecrawl({
  apiKey: process.env.DARKCRAWL_API_KEY,
  apiUrl: 'https://api.darkcrawl.dev',
});
const doc = await firecrawl.scrape('http://exampleonionq7x2mfk4lzr5w3ty6hbnc2jdu7avs4ekp5gw3xmlq2zr.onion/notice', { formats: ['markdown'] });
console.log(doc.markdown);

The same client does the rest of Firecrawl’s calls. The crawl waits for the job to finish. The agent is started and read as two calls.

Node
const site = 'http://exampleonionq7x2mfk4lzr5w3ty6hbnc2jdu7avs4ekp5gw3xmlq2zr.onion/notice';
const job = await firecrawl.crawl(site, { limit: 10 });
const { links } = await firecrawl.map(site);
const started = await firecrawl.startAgent({ urls: [site], prompt: 'Where did the mirror list move?' });
const status = await firecrawl.getAgentStatus(started.id);
  • Stored copies. The SDK sends no maxAge by default, so a scrape is fresh. Pass maxAge in milliseconds to accept a stored copy, and maxAge: 0 for a fresh page.
  • Retries. The SDK sends a request again when it gets a 502, up to 3 times by default, and DarkCrawl uses 502 for ONION_UNREACHABLE and GATED. To send it once, create the client with maxRetries: 1.
Node
import { Firecrawl } from 'firecrawl';

const firecrawl = new Firecrawl({
  apiKey: process.env.DARKCRAWL_API_KEY,
  apiUrl: 'https://api.darkcrawl.dev',
  maxRetries: 1,
});

const doc = await firecrawl.scrape('http://exampleonionq7x2mfk4lzr5w3ty6hbnc2jdu7avs4ekp5gw3xmlq2zr.onion/notice', { formats: ['markdown'], maxAge: 0 });
  • Replies as sent. The SDK returns documents as DarkCrawl sends them: indicators, resources, a search result’s captureId and fetchedAt, and the agent’s sources are all there.
  • Monitors. The SDK sends monitor requests as given, so channelIds and a search target’s sources work.
  • Parse. The SDK sends parse options as given, and its upload carries a Content-Length.
Node
const doc = await firecrawl.parse('./report.pdf');
  • Agent. The blocking agent() returns on its timeout with the last status it read, which can still be processing. Poll getAgentStatus. A cancelled job reads failed with error: "Agent was cancelled", and a second cancel once it has stopped raises with 409. startAgent with a webhook raises with 400 NOT_IMPLEMENTED.
  • Extract. startExtract raises with the 501 refusal. Use the agent.

The codes DarkCrawl answers with are on Errors.