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.
// 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.
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);Things to know
Section titled “Things to know”- Stored copies. The SDK sends no
maxAgeby default, so a scrape is fresh. PassmaxAgein milliseconds to accept a stored copy, andmaxAge: 0for 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_UNREACHABLEandGATED. To send it once, create the client withmaxRetries: 1.
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’scaptureIdandfetchedAt, and the agent’ssourcesare all there. - Monitors. The SDK sends monitor requests as given, so
channelIdsand a search target’ssourceswork. - Parse. The SDK sends parse options as given, and its upload carries a
Content-Length.
const doc = await firecrawl.parse('./report.pdf');- Agent. The blocking
agent()returns on itstimeoutwith the last status it read, which can still beprocessing. PollgetAgentStatus. A cancelled job readsfailedwitherror: "Agent was cancelled", and a second cancel once it has stopped raises with409.startAgentwith awebhookraises with400 NOT_IMPLEMENTED. - Extract.
startExtractraises with the501refusal. Use the agent.
The codes DarkCrawl answers with are on Errors.