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

# DirectoryLoader integration

> Integrate with the DirectoryLoader document loader using LangChain JavaScript.

<Tip>
  **Compatibility**: Only available on Node.js.
</Tip>

This notebook provides a quick overview for getting started with `DirectoryLoader` [document loaders](/oss/javascript/integrations/document_loaders). For detailed documentation of all `DirectoryLoader` features and configurations head to the [API reference](https://reference.langchain.com/javascript/langchain-core/document_loaders/base/BaseDocumentLoader).

This example goes over how to load data from folders with multiple files. The second argument is a map of file extensions to loader factories. Each file will be passed to the matching loader, and the resulting documents will be concatenated together.

Example folder:

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
src/document_loaders/example_data/example/
├── example.json
├── example.jsonl
├── example.txt
└── example.csv
```

## Overview

### Integration details

| Class                                                                                                                   | Package                                              | Compatibility | Local | PY support |
| :---------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------- | :-----------: | :---: | :--------: |
| [`DirectoryLoader`](https://reference.langchain.com/javascript/langchain-core/document_loaders/base/BaseDocumentLoader) | [langchain](https://www.npmjs.com/package/langchain) |   Node-only   |   ✅   |      ✅     |

## Setup

To access `DirectoryLoader` document loader you'll need to install the `langchain` package.

### Installation

The LangChain DirectoryLoader integration lives in the `langchain` package:

<CodeGroup>
  ```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  npm install langchain @langchain/core
  ```

  ```bash yarn theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  yarn add langchain @langchain/core
  ```

  ```bash pnpm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pnpm add langchain @langchain/core
  ```
</CodeGroup>

## Instantiation

Now we can instantiate our model object and load documents:

<Warning>
  The `@langchain/community` package is no longer maintained. Examples that import from `@langchain/community` may be outdated or broken. Use with caution.
</Warning>

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { DirectoryLoader } from "@langchain/classic/document_loaders/fs/directory";
import {
  JSONLoader,
  JSONLinesLoader,
} from "@langchain/classic/document_loaders/fs/json";
import { TextLoader } from "@langchain/classic/document_loaders/fs/text";
import { CSVLoader } from "@langchain/community/document_loaders/fs/csv";

const loader = new DirectoryLoader(
  "../../../../../../examples/src/document_loaders/example_data",
  {
    ".json": (path) => new JSONLoader(path, "/texts"),
    ".jsonl": (path) => new JSONLinesLoader(path, "/html"),
    ".txt": (path) => new TextLoader(path),
    ".csv": (path) => new CSVLoader(path, "text"),
  }
);
```

## Load

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const docs = await loader.load()
// disable console.warn calls
console.warn = () => {}
docs[0]
```

```javascript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
Document {
  pageContent: 'Foo\nBar\nBaz\n\n',
  metadata: {
    source: '/Users/bracesproul/code/lang-chain-ai/langchainjs/examples/src/document_loaders/example_data/example.txt'
  },
  id: undefined
}
```

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
console.log(docs[0].metadata)
```

```javascript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{
  source: '/Users/bracesproul/code/lang-chain-ai/langchainjs/examples/src/document_loaders/example_data/example.txt'
}
```

***

## API reference

For detailed documentation of all `DirectoryLoader` features and configurations head to the [API reference](https://reference.langchain.com/javascript/langchain-core/document_loaders/base/BaseDocumentLoader).

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/javascript/integrations/document_loaders/file_loaders/directory.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
