> ## 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.

# LocalFileStore integration

> Integrate with the LocalFileStore store using LangChain JavaScript.

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

This will help you get started with [`LocalFileStore`](/oss/javascript/integrations/stores). For detailed documentation of all `LocalFileStore` features and configurations head to the [API reference](https://reference.langchain.com/javascript/langchain/storage/file_system/LocalFileStore).

## Overview

The `LocalFileStore` is a wrapper around the `fs` module for storing data as key-value pairs.
Each key value pair has its own file nested inside the directory passed to the `.fromPath` method.
The file name is the key and inside contains the value of the key.

<Info>
  **The path passed to the `.fromPath` must be a directory, not a file.**
</Info>

<Warning>
  **This file store can alter any text file in the provided directory and any subfolders.**

  Make sure that the path you specify when initializing the store is free of other files.
</Warning>

### Integration details

| Class                                                                                                       | Package                                              | Local | [PY support](https://python.langchain.com/docs/integrations/stores/file_system/) |                                         Downloads                                         |                                         Version                                        |
| :---------------------------------------------------------------------------------------------------------- | :--------------------------------------------------- | :---: | :------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------: |
| [`LocalFileStore`](https://reference.langchain.com/javascript/langchain/storage/file_system/LocalFileStore) | [langchain](https://www.npmjs.com/package/langchain) |   ✅   |                                         ✅                                        | ![NPM - Downloads](https://img.shields.io/npm/dm/langchain?style=flat-square\&label=%20&) | ![NPM - Version](https://img.shields.io/npm/v/langchain?style=flat-square\&label=%20&) |

## Setup

### Installation

The LangChain `LocalFileStore` 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 byte store:

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { LocalFileStore } from "@langchain/classic/storage/file_system"

const kvStore = await LocalFileStore.fromPath("./messages");
```

Define an encoder and decoder for converting the data to `Uint8Array` and back:

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const encoder = new TextEncoder();
const decoder = new TextDecoder();
```

## Usage

You can set data under keys like this using the `mset` method:

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
await kvStore.mset(
  [
    ["key1", encoder.encode("value1")],
    ["key2", encoder.encode("value2")],
  ]
)

const results = await kvStore.mget(
  [
    "key1",
    "key2",
  ]
)
console.log(results.map((v) => decoder.decode(v)));
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
[ 'value1', 'value2' ]
```

And you can delete data using the `mdelete` method:

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
await kvStore.mdelete(
  [
    "key1",
    "key2",
  ]
)

await kvStore.mget(
  [
    "key1",
    "key2",
  ]
)
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
[ undefined, undefined ]
```

## Yielding values

If you want to get back all the keys you can call the `yieldKeys` method. Optionally, you can pass a key prefix to only get back keys which match that prefix.

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { LocalFileStore } from "@langchain/classic/storage/file_system"

const kvStoreForYield = await LocalFileStore.fromPath("./messages");

const encoderForYield = new TextEncoder();

// Add some data to the store
await kvStoreForYield.mset(
  [
    ["message:id:key1", encoderForYield.encode("value1")],
    ["message:id:key2", encoderForYield.encode("value2")],
  ]
)

const yieldedKeys = [];
for await (const key of kvStoreForYield.yieldKeys("message:id:")) {
  yieldedKeys.push(key);
}

console.log(yieldedKeys);
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
[ 'message:id:key1', 'message:id:key2' ]
```

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import fs from "fs";

// Cleanup
await fs.promises.rm("./messages", { recursive: true, force: true });
```

***

## API reference

For detailed documentation of all `LocalFileStore` features and configurations, head to the [API reference](https://reference.langchain.com/javascript/langchain/storage/file_system/LocalFileStore)

***

<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/stores/file_system.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
