*   [](/v0.2/)
*   [How-to guides](/v0.2/docs/how_to/)
*   How to write a custom document loader

On this page

How to write a custom document loader
=====================================

If you want to implement your own Document Loader, you have a few options.

### Subclassing `BaseDocumentLoader`[​](#subclassing-basedocumentloader "Direct link to subclassing-basedocumentloader")

You can extend the `BaseDocumentLoader` class directly. The `BaseDocumentLoader` class provides a few convenience methods for loading documents from a variety of sources.

    abstract class BaseDocumentLoader implements DocumentLoader {  abstract load(): Promise<Document[]>;}

### Subclassing `TextLoader`[​](#subclassing-textloader "Direct link to subclassing-textloader")

If you want to load documents from a text file, you can extend the `TextLoader` class. The `TextLoader` class takes care of reading the file, so all you have to do is implement a parse method.

    abstract class TextLoader extends BaseDocumentLoader {  abstract parse(raw: string): Promise<string[]>;}

### Subclassing `BufferLoader`[​](#subclassing-bufferloader "Direct link to subclassing-bufferloader")

If you want to load documents from a binary file, you can extend the `BufferLoader` class. The `BufferLoader` class takes care of reading the file, so all you have to do is implement a parse method.

    abstract class BufferLoader extends BaseDocumentLoader {  abstract parse(    raw: Buffer,    metadata: Document["metadata"]  ): Promise<Document[]>;}

* * *

#### Was this page helpful?

  

#### You can also leave detailed feedback [on GitHub](https://github.com/langchain-ai/langchainjs/issues/new?assignees=&labels=03+-+Documentation&projects=&template=documentation.yml&title=DOC%3A+%3CPlease+write+a+comprehensive+title+after+the+%27DOC%3A+%27+prefix%3E).

[

Previous

How to load CSV data

](/v0.2/docs/how_to/document_loader_csv)[

Next

How to load data from a directory

](/v0.2/docs/how_to/document_loader_directory)

*   [Subclassing `BaseDocumentLoader`](#subclassing-basedocumentloader)
*   [Subclassing `TextLoader`](#subclassing-textloader)
*   [Subclassing `BufferLoader`](#subclassing-bufferloader)