# Local File System

> Read/Write files on host machine.

Source: https://docs.sommatic.ai/en/nodes/io.local.file/

- Slug: `io.local.file`
- Family: Input and output
- Version: 1.0.0
- Status: Available
- Execution: async

Read/Write files on host machine.

## Configuration

- `path` (string, required): Absolute path
- `operation` (string, required): Default: `read`. Allowed values: `read`, `write`, `append`, `delete`, `list`.
- `content` (string, optional): Content to write/append
- `encoding` (string, optional): Default: `utf8`.

## Output ports

- `out` (default): FS operation succeeded
- `error`: FS operation failed

## Input contract

- `path` (string, required)
- `operation` (string, required)
- `content` (string, optional)
- `encoding` (string, optional)

## Output contract

- `result` (string, optional): File content or operation success status

## In expressions

What a later node can read from this node's output with `$("Local File System").item.json.<path>` (write your node's label instead of `Local File System`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("Local File System").item.json.result` (string) = `{…}`: File content or operation success status
- `$("Local File System").item.json.result.written` (boolean) = `true` (Not suggested by the editor)
- `$("Local File System").item.json.result.path` (string) = `"/data/exports/orders-2026-11-25.csv"` (Not suggested by the editor)


## How it works

Reads, writes, appends, deletes or lists a path on the file system of the host that runs the worker.

1. Resolves the config. `path`, `operation` (default `read`), `content` (default empty) and `encoding` (default `utf8`) fall back to the same keys of the incoming payload.
2. Fails through `error` when `path` is empty.
3. Runs the operation: `read` returns the file content decoded with `encoding`; `write` replaces the file with `content`; `append` adds `content` at the end; `delete` removes the file; `list` returns the entry names of a directory.
4. Returns `{ result }` through `out`; any file system error leaves through `error`.

## In a workflow

### Node

```json
{
  "node_id": "node-write-export",
  "label": "Write export",
  "operator_slug": "io.local.file",
  "operator_version": "1.0.0",
  "config": {
    "path": "/data/exports/orders-{{ $json.date }}.csv",
    "operation": "write",
    "content": "{{ $json.csv }}"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "result": {
      "written": true,
      "path": "/data/exports/orders-2026-11-25.csv"
    }
  },
  "port": "out"
}
```

## Output ports (behaviour in the code)

### `out`

The operation succeeded. `result` is the text for `read`, an array of names for `list`, and `{ written | appended | deleted: true, path }` for the others.

```json
{
  "result": {
    "written": true,
    "path": "/data/exports/orders-2026-11-25.csv"
  }
}
```

### `error`

`path` is missing, the operation is unknown, or the file system rejected the call.

```json
{
  "error": "ENOENT: no such file or directory, open '/data/exports/missing.csv'"
}
```

## Behaviour in the code

- `encoding`: Applied only to `read`. `write` and `append` always write UTF-8 text.
- `path`: A relative path is resolved against the working directory of the orchestrator process.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `path is required` | `error` | No path in the config nor in the incoming payload. Use an absolute path. |
| `Unsupported operation: <operation>` | `error` | `operation` is not `read`, `write`, `append`, `delete` or `list`. |
| `ENOENT: no such file or directory, <syscall> '<path>'` | `error` | The file or its parent directory does not exist on the host. `write` and `append` do not create missing directories. |
| `EACCES: permission denied, <syscall> '<path>'` | `error` | The orchestrator process has no permission on that path. |

## Notes and limits

- The path refers to the host or container that runs the worker, which may be ephemeral; files written there do not persist across deployments.
- `write` overwrites without confirmation and `delete` is permanent. `list` does not recurse.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "io.local.file",
  "name": "Local File System",
  "category": "io",
  "version": "1.0.0",
  "description": "Read/Write files on host machine.",
  "capabilities": [
    "fs",
    "local",
    "file"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "path": {
        "type": "string",
        "description": "Absolute path"
      },
      "operation": {
        "type": "string",
        "enum": [
          "read",
          "write",
          "append",
          "delete",
          "list"
        ],
        "default": "read"
      },
      "content": {
        "type": "string",
        "description": "Content to write/append"
      },
      "encoding": {
        "type": "string",
        "default": "utf8"
      }
    },
    "required": [
      "path",
      "operation"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "path": {
        "type": "string"
      },
      "operation": {
        "type": "string"
      },
      "content": {
        "type": "string"
      },
      "encoding": {
        "type": "string"
      }
    },
    "required": [
      "path",
      "operation"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "result": {
        "type": "string",
        "description": "File content or operation success status"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Result",
      "description": "FS operation succeeded",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "FS operation failed",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "desktop-agent",
    "local-agent"
  ],
  "tags": [
    "local",
    "files"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "path": {
      "type": "string",
      "description": "Absolute path"
    },
    "operation": {
      "type": "string",
      "enum": [
        "read",
        "write",
        "append",
        "delete",
        "list"
      ],
      "default": "read"
    },
    "content": {
      "type": "string",
      "description": "Content to write/append"
    },
    "encoding": {
      "type": "string",
      "default": "utf8"
    }
  },
  "required": [
    "path",
    "operation"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "path": {
      "type": "string"
    },
    "operation": {
      "type": "string"
    },
    "content": {
      "type": "string"
    },
    "encoding": {
      "type": "string"
    }
  },
  "required": [
    "path",
    "operation"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "result": {
      "type": "string",
      "description": "File content or operation success status"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Result",
    "description": "FS operation succeeded",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "FS operation failed",
    "is_default": false,
    "supports_condition": false
  }
]
```
