AutomationFlowsGeneral › File-Based Key-Value Store Writer

File-Based Key-Value Store Writer

Original n8n title: Simple File Based Key Value Store Writekey

Simple File Based Key Value Store Writekey. Uses manualTrigger, writeBinaryFile, functionItem, readBinaryFiles. Event-driven trigger; 10 nodes.

Event trigger★★★★☆ complexity10 nodesWrite Binary FileFunction ItemRead Binary FilesMove Binary Data
General Trigger: Event Nodes: 10 Complexity: ★★★★☆ Added:

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "nodes": [
    {
      "name": "On clicking 'execute'",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        60,
        300
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "name": "Write Binary File",
      "type": "n8n-nodes-base.writeBinaryFile",
      "position": [
        420,
        740
      ],
      "parameters": {
        "fileName": "={{$node[\"Config\"].json[\"file\"]}}",
        "dataPropertyName": "=data"
      },
      "typeVersion": 1
    },
    {
      "name": "Config",
      "type": "n8n-nodes-base.functionItem",
      "position": [
        600,
        300
      ],
      "parameters": {
        "functionCode": "return {\n  file: '/home/node/.n8n/local-files' + item.file,\n  key: item.key,\n  value: item.value\n}"
      },
      "typeVersion": 1
    },
    {
      "name": "Read Binary Files",
      "type": "n8n-nodes-base.readBinaryFiles",
      "position": [
        240,
        520
      ],
      "parameters": {
        "fileSelector": "={{$json[\"file\"]}}"
      },
      "typeVersion": 1,
      "continueOnFail": true,
      "alwaysOutputData": true
    },
    {
      "name": "SetKeyValue",
      "type": "n8n-nodes-base.functionItem",
      "position": [
        600,
        520
      ],
      "parameters": {
        "functionCode": "const key = $node[\"Config\"].json[\"key\"]\nconst value = $node[\"Config\"].json[\"value\"]\nitem[key] = value\n\nreturn item;"
      },
      "typeVersion": 1
    },
    {
      "name": "BinaryToJSON",
      "type": "n8n-nodes-base.moveBinaryData",
      "position": [
        420,
        520
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "name": "JSONToBinary",
      "type": "n8n-nodes-base.moveBinaryData",
      "position": [
        240,
        740
      ],
      "parameters": {
        "mode": "jsonToBinary",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        420,
        300
      ],
      "parameters": {
        "options": {},
        "batchSize": 1
      },
      "typeVersion": 1
    },
    {
      "name": "Repeat",
      "type": "n8n-nodes-base.if",
      "position": [
        600,
        740
      ],
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$node[\"SplitInBatches\"].context[\"noItemsLeft\"]}}",
              "value2": true
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "name": "Done",
      "type": "n8n-nodes-base.functionItem",
      "position": [
        800,
        740
      ],
      "parameters": {
        "functionCode": "console.log('Done!');\n\nreturn item;"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Config": {
      "main": [
        [
          {
            "node": "Read Binary Files",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Repeat": {
      "main": [
        [
          {
            "node": "Done",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SetKeyValue": {
      "main": [
        [
          {
            "node": "JSONToBinary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "BinaryToJSON": {
      "main": [
        [
          {
            "node": "SetKeyValue",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "JSONToBinary": {
      "main": [
        [
          {
            "node": "Write Binary File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Binary Files": {
      "main": [
        [
          {
            "node": "BinaryToJSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Binary File": {
      "main": [
        [
          {
            "node": "Repeat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On clicking 'execute'": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

How this works

This workflow provides a straightforward way to store and update key-value pairs in a simple file-based database, enabling quick persistence of data without relying on complex external services. It's ideal for developers or automation enthusiasts building lightweight applications that need to retain settings, user preferences, or session data across runs. The key step involves using the writeBinaryFile node to save JSON-formatted key-value data to a file, with functionItem nodes handling the formatting and readBinaryFiles ensuring seamless retrieval for updates.

Use this workflow when you require an event-driven, on-demand key-value store for small-scale automations, such as logging simple metrics or caching API responses in a self-hosted environment. Avoid it for high-volume or concurrent access scenarios, where a proper database like PostgreSQL would be more reliable. Common variations include adding encryption via function nodes for sensitive data or integrating with email triggers to notify on updates.

About this workflow

Simple File Based Key Value Store Writekey. Uses manualTrigger, writeBinaryFile, functionItem, readBinaryFiles. Event-driven trigger; 10 nodes.

Source: https://github.com/Zie619/n8n-workflows — original creator credit. Request a take-down →

More General workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

General

Create 2 Xml Files With And Without Xml Attributes. Uses manualTrigger, mySql, itemLists, xml. Event-driven trigger; 13 nodes.

MySQL, Item Lists, XML +2
General

Simple File Based Key Value Store Getkey. Uses manualTrigger, functionItem, readBinaryFile, moveBinaryData. Event-driven trigger; 5 nodes.

Function Item, Read Binary File, Move Binary Data
General

Standup Bot 1 4 Initialize. Uses manualTrigger, writeBinaryFile, moveBinaryData. Event-driven trigger; 4 nodes.

Write Binary File, Move Binary Data
General

Standup Bot - Initialize. Uses manualTrigger, writeBinaryFile, moveBinaryData. Event-driven trigger; 4 nodes.

Write Binary File, Move Binary Data
General

Standup Bot 3 4 Override Config. Uses manualTrigger, writeBinaryFile, moveBinaryData. Event-driven trigger; 3 nodes.

Write Binary File, Move Binary Data