Overview
This node provides simple key-value storage functionality using JSON files. It allows users to save a value under a specific key or read a value by its key from a named file. This is useful for persisting small amounts of data between workflow executions without requiring an external database or service.
Common scenarios include:
- Caching API tokens or temporary data.
- Storing user preferences or state information.
- Sharing data between different parts of a workflow or across workflows.
For example, you can save a session token with a key "sessionToken" in a file named "myFile", and later read it back when needed.
Properties
| Name | Meaning |
|---|---|
| File | The name of the JSON file where key-value pairs are saved or read from (e.g., "myFile"). |
| Key | The key string used to save or retrieve a value (e.g., "exampleKey"). |
Note: For the "Read" operation, only "File" and "Key" are required inputs.
Output
The node outputs a single JSON object with the following structure depending on the operation:
Save operation:
{ "<key>": { "value": "<saved_value>", "operation": "save", "status": "Saved" } }Where
<key>is the key used to save the value.Read operation:
{ "key": "<key>", "value": "<retrieved_value_or_null>", "operation": "read" }If the key does not exist in the file, the value will be
null.
The output is always returned as an array containing one item with this JSON data.
Dependencies
- Uses Node.js built-in
fsandpathmodules for file system operations. - Stores data in JSON files located in a subdirectory named
datarelative to the node's source directory. - No external APIs or credentials are required.
Troubleshooting
- File access errors: Ensure the n8n process has write/read permissions to the
datadirectory where files are stored. - Missing keys on read: If a key does not exist in the file, the node returns
nullfor the value. Verify the key spelling and that the save operation was successful. - Corrupted JSON files: Manual edits or concurrent writes might corrupt the JSON file causing parse errors. Deleting or fixing the file may resolve issues.
- Concurrent writes: Since the node reads and writes the entire JSON file, simultaneous executions could cause race conditions leading to lost data.