> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# TextLoader 集成

> 使用 LangChain JavaScript 集成 TextLoader 文档加载器。

> [!TIP]
>
> **兼容性**：仅在 Node.js 上可用。

此笔记本提供了快速入门 `TextLoader` [文档加载器](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/document_loaders.md) 的概述。有关所有 `TextLoader` 功能和配置的详细文档，请访问 [API 参考](https://reference.langchain.com/javascript/langchain-core/document_loaders/base/BaseDocumentLoader)。

## 概述

### 集成细节

| 类 | 包 | 兼容性 | 本地 | PY 支持 |
| :- | :- | :-: | :-: | :-: |
| [`TextLoader`](https://reference.langchain.com/javascript/langchain-core/document_loaders/base/BaseDocumentLoader) | [langchain](https://www.npmjs.com/package/langchain) | 仅 Node.js | ✅ | ❌ |

## 设置

要访问 `TextLoader` 文档加载器，您需要安装 `langchain` 包。

### 安装

LangChain TextLoader 集成位于 `langchain` 包中：

```bash npm theme={null}
npm install langchain
```

```bash yarn theme={null}
yarn add langchain
```

```bash pnpm theme={null}
pnpm add langchain
```

## 实例化

现在我们可以实例化我们的模型对象并加载文档：

```typescript theme={null}
import { TextLoader } from "@langchain/classic/document_loaders/fs/text"

const loader = new TextLoader("../../../../../../examples/src/document_loaders/example_data/example.txt")
```

## 加载

```typescript theme={null}
const docs = await loader.load()
docs[0]
```

```javascript theme={null}
Document {
  pageContent: 'Foo\nBar\nBaz\n\n',
  metadata: {
    source: '../../../../../../examples/src/document_loaders/example_data/example.txt'
  },
  id: undefined
}
```

```typescript theme={null}
console.log(docs[0].metadata)
```

```javascript theme={null}
{
  source: '../../../../../../examples/src/document_loaders/example_data/example.txt'
}
```

***

## API 参考

有关所有 `TextLoader` 功能和配置的详细文档，请访问 [API 参考](https://reference.langchain.com/javascript/langchain-core/document_loaders/base/BaseDocumentLoader)。

***

> 官方原文：[src/oss/javascript/integrations/document\_loaders/file\_loaders/text.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/javascript/integrations/document_loaders/file_loaders/text.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.