> For the complete documentation index, see [llms.txt](https://docs.mindee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mindee.com/v1/integration/nodejs-sdk.md).

# Node.js OCR SDK

## Mindee API Helper Library for Node.js

Quickly and easily connect to Mindee's API services using Node.js.

### Quick Start

Here's the TL;DR of getting started.

First, get an [API Key](/v1/get-started/create-api-key.md)

Then, install this library:

```shell
npm install mindee@^5.0.0
```

Finally, Node.js away!

#### Loading a File and Parsing It

**Global Documents**

```js
const mindee = require("mindee");
// for TS or modules:
// import * as mindee from "mindee";

// Init a new client
const mindeeClient = new mindee.v1.Client({ apiKey: "my-api-key" });

// Load a file from disk
const filePath = "/path/to/the/file.ext";
const inputSource = new mindee.PathInput({ inputPath: filePath });

// Parse it on the API of your choice
const apiResponse = mindeeClient.parse(
  mindee.v1.product.InvoiceV4, inputSource
);
```

**Note:** Files can also be loaded from:

A base64 encoded string:

```js
const b64String = "iVBORw0KGgoAAAANSUhEUgAAABgAAA ...";
const inputSource = new mindee.Base64Input({
  inputString: b64String,
  filename: "base64_file.txt",
});
```

A byte sequence:

```js
const inputBytes = await fs.promises.readFile("/path/to/the/file.ext");
const inputSource = new mindee.BytesInput({
  inputBytes: inputBytes,
  filename: "file.ext",
});
```

A stream:

```js
const stream = fs.createReadStream("/path/to/the/file.ext");
const inputSource = new mindee.StreamInput({
  inputStream: stream,
  filename: "file.ext",
});
```

A buffer:

```js
const buffer = Buffer.from(
  await fs.promises.readFile("/path/to/the/file.ext")
);
const inputSource = new mindee.BufferInput({
  buffer: buffer,
  filename: "file.ext",
});
```

A URL (`https` only):

```js
const inputSource = new mindee.UrlInput({
  url: "https://example.com/file.ext"
});
```

You can also load the document locally before sending it:

```js
const inputSource = new mindee.UrlInput({
  url: "https://example.com/file.ext"
});
await inputSource.init();
const localInputSource = inputSource.asLocalInputSource();
```

**Note:** Files hidden behind redirections are rejected by the server; this solution helps to circumvent that issue.

**Region-Specific Documents**

Region-Specific Documents use the following syntax:

```js
const mindee = require("mindee");
// for TS or modules:
// import * as mindee from "mindee";

const mindeeClient = new mindee.v1.Client({ apiKey: "my-api-key" });

const filePath = "/path/to/the/file.ext";
const inputSource = new mindee.PathInput({ inputPath: filePath });

// The IdCardV1 product belongs to mindee.v1.product.fr, not mindee.product itself
const apiResponse = mindeeClient.parse(mindee.v1.product.fr.IdCardV1, inputSource);
```

**Custom Documents (docTI & Custom APIs)**

Custom documents will require you to provide their endpoint manually.

```js
const mindee = require("mindee");
// for TS or modules:
// import * as mindee from "mindee";

// Init a new client
const mindeeClient = new mindee.v1.Client({
  apiKey: "my-api-key"
});

// Load a file from disk
const filePath = "/path/to/the/file.ext";
const inputSource = new mindee.PathInput({ inputPath: filePath });

// Create a custom endpoint for your product
const customEndpoint = mindeeClient.createEndpoint(
  "my-endpoint",
  "my-account",
  "my-version" // will default to 1 if not provided
);

// Parse it
const apiResponse = await mindeeClient
  .enqueueAndParse(
    mindee.v1.product.GeneratedV1,
    inputSource,
    {
      endpoint: customEndpoint
    }
  );
```

#### Handling the Return

```js
// Handle the response Promise
apiResponse.then((resp) => {
    // print a string summary
    console.log(resp.document.toString());

    // individual pages (array)
    console.log(res.document.inference.pages);
});
```

#### Additional Options

Options to pass when sending a file to be parsed.

**Page Options**

Allows only sending certain pages in a PDF.

In this example we only send the first, penultimate, and last pages:

```js
const apiResponse = mindeeClient.parse(
  mindee.v1.product.InvoiceV4,
  inputSource,
  {
    pageOptions: {
      pageIndexes: [0, -2, -1],
      operation: mindee.PageOptionsOperation.KeepOnly,
      onMinPages: 2
    }
  });
```

### Further Reading

Take a look at the [**Reference Documentation**](https://mindee.github.io/mindee-api-nodejs/).

### License

Copyright © Mindee

Available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mindee.com/v1/integration/nodejs-sdk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
