> ## Documentation Index
> Fetch the complete documentation index at: /llms.txt
> Use this file to discover all available pages before exploring further.

# Node

> Screenshot, search, scrape and crawl the web with the ScreenshotRender Node SDK.

## Installation

To install the ScreenshotRender Node SDK, use npm:

```bash Node
npm install screenshotrender
```

It runs on Node 18 or later, has no dependencies, and ships types.

## Usage

1. Get an API key from your [dashboard](https://www.screenshotrender.com/dashboard). New accounts start with 100 free credits.
2. Pass it to the client as `apiKey`, or set it in the `SCREENSHOTRENDER_API_KEY` environment variable.

Each method returns the response's `data`, so you read fields like `doc.markdown` directly.

### Taking a screenshot

```js Node
import ScreenshotRender from "screenshotrender";

const screenshotrender = new ScreenshotRender({ apiKey: "sr-YOUR-API-KEY" });

const shot = await screenshotrender.screenshot("https://example.com");
console.log(shot.screenshot); // the image's URL
```

Capture the full page, at a window size you choose:

```js Node
import ScreenshotRender from "screenshotrender";

const screenshotrender = new ScreenshotRender({ apiKey: "sr-YOUR-API-KEY" });

const shot = await screenshotrender.screenshot("https://www.screenshotrender.com", {
  fullPage: true,
  viewport: { width: 1440, height: 900 },
});
console.log(shot.screenshot);
```

### Searching the web

```js Node
import ScreenshotRender from "screenshotrender";

const screenshotrender = new ScreenshotRender({ apiKey: "sr-YOUR-API-KEY" });

const results = await screenshotrender.search("open source vector databases", {
  limit: 2,
  scrapeOptions: { formats: ["markdown"] },
});

for (const result of results.web ?? []) {
  console.log(result.url, result.markdown?.length, "characters");
}
```

### Scraping a URL

```js Node
import ScreenshotRender from "screenshotrender";

const screenshotrender = new ScreenshotRender({ apiKey: "sr-YOUR-API-KEY" });

const doc = await screenshotrender.scrape("https://example.com", {
  formats: ["markdown", "html"],
});
console.log(doc.markdown);
```

### Extracting structured data

```js Node
import ScreenshotRender from "screenshotrender";

const screenshotrender = new ScreenshotRender({ apiKey: "sr-YOUR-API-KEY" });

const schema = {
  type: "object",
  properties: {
    stories: {
      type: "array",
      items: {
        type: "object",
        properties: { title: { type: "string" }, points: { type: "number" } },
        required: ["title", "points"],
      },
    },
  },
  required: ["stories"],
};

const doc = await screenshotrender.scrape("https://news.ycombinator.com", {
  formats: [{ type: "json", prompt: "The top 3 stories", schema }],
});
console.log(doc.json);
```

### Parsing documents

From a URL:

```js Node
import ScreenshotRender from "screenshotrender";

const screenshotrender = new ScreenshotRender({ apiKey: "sr-YOUR-API-KEY" });

const paper = await screenshotrender.parse("https://arxiv.org/pdf/1706.03762", {
  parsers: [{ type: "pdf", maxPages: 2 }],
});
console.log(paper.markdown);
```

From a file you upload:

```js Node
import { readFile } from "node:fs/promises";
import ScreenshotRender from "screenshotrender";

const screenshotrender = new ScreenshotRender({ apiKey: "sr-YOUR-API-KEY" });

const report = await screenshotrender.parse({
  data: await readFile("report.pdf"),
  filename: "report.pdf",
});
console.log(report.markdown);
```

### Mapping a website

```js Node
import ScreenshotRender from "screenshotrender";

const screenshotrender = new ScreenshotRender({ apiKey: "sr-YOUR-API-KEY" });

const site = await screenshotrender.map("https://docs.python.org/3/", { limit: 5 });

for (const link of site.links) {
  console.log(link.url, link.title);
}
```

### Crawling a website

`crawl()` starts the crawl, waits for it and returns every page. `onProgress` is called after every status check.

```js Node
import ScreenshotRender from "screenshotrender";

const screenshotrender = new ScreenshotRender({ apiKey: "sr-YOUR-API-KEY" });

const crawl = await screenshotrender.crawl("https://docs.python.org/3/tutorial/", {
  limit: 3,
  onProgress: (job) => console.log(`${job.completed} of ${job.total} pages`),
});

console.log(crawl.status, crawl.creditsUsed, "credits");
for (const page of crawl.data) {
  console.log(page.metadata?.sourceURL);
}
```

### Start a crawl

To start a crawl without waiting, use `startCrawl()` and keep the `id`:

```js Node
import ScreenshotRender from "screenshotrender";

const screenshotrender = new ScreenshotRender({ apiKey: "sr-YOUR-API-KEY" });

const job = await screenshotrender.startCrawl("https://docs.python.org/3/tutorial/", { limit: 3 });
console.log(job.id);
```

### Checking crawl status

```js Node
import ScreenshotRender from "screenshotrender";

const screenshotrender = new ScreenshotRender({ apiKey: "sr-YOUR-API-KEY" });

const job = await screenshotrender.getCrawlStatus("YOUR_CRAWL_ID");
console.log(job.status, `${job.completed} of ${job.total} pages`);
```

### Cancelling a crawl

```js Node
import ScreenshotRender from "screenshotrender";

const screenshotrender = new ScreenshotRender({ apiKey: "sr-YOUR-API-KEY" });

const stopped = await screenshotrender.cancelCrawl("YOUR_CRAWL_ID");
console.log(stopped); // false when the crawl had already finished
```

### Failed and blocked pages

```js Node
import ScreenshotRender from "screenshotrender";

const screenshotrender = new ScreenshotRender({ apiKey: "sr-YOUR-API-KEY" });

const { errors, robotsBlocked } = await screenshotrender.getCrawlErrors("YOUR_CRAWL_ID");
console.log(errors, robotsBlocked);
```

## Error handling

Every failure is a `ScreenshotRenderError` with the HTTP `status`, the API's error `code` and its `message`. See [Errors](/api-reference/errors.md) for every code.

```js Node
import ScreenshotRender, { ScreenshotRenderError } from "screenshotrender";

const screenshotrender = new ScreenshotRender({ apiKey: "sr-not-a-real-key" });

try {
  await screenshotrender.scrape("https://example.com");
} catch (err) {
  if (err instanceof ScreenshotRenderError) {
    console.log(err.status, err.code, err.message); // 401 invalid_api_key Invalid API key.
  }
}
```
