File Global Variable icon

File Global Variable

Manage global variables via a JSON file

Overview

This node manages global variables stored in a JSON file on the filesystem. It allows you to get, set, delete, list all, or delete all variables saved in a specified JSON file. This is useful for workflows that need persistent storage of key-value pairs outside of n8n’s internal context, enabling sharing of data across different workflow executions or nodes.

Common scenarios include:

  • Storing configuration values or tokens that multiple workflows can access.
  • Persisting state information between workflow runs.
  • Managing feature flags or environment-specific settings without hardcoding them into workflows.

For example, you could use this node to store API keys or user preferences in a JSON file and retrieve or update them dynamically during workflow execution.

Properties

Name Meaning
Operation The action to perform: Get, Set, Delete, List ALL, or Delete All
Key(Separate Multiple Items with Commas in English) The key(s) to get, set, or delete. Multiple keys can be separated by commas (for Get, Set, Delete operations).
Value The value to set for the given key(s) (only used with the Set operation).
Type The data type of the value being set: String, Number, Boolean, Object, or Array.
File Path The path to the JSON file where variables are stored. Defaults to ~/.n8n/global_variables.json.

Output

The output is a JSON object describing the result of the operation:

  • For Get:
    An array of objects with each containing a key and its corresponding value (or null if not found).

  • For Set:
    Confirmation of success and the list of keys set.

  • For Delete:
    Lists of keys successfully deleted and keys not found.

  • For List ALL:
    The entire JSON object representing all stored variables.

  • For Delete All:
    No specific output other than an empty JSON object indicating all variables were cleared.

No binary data is output by this node.

Example output for a Get operation:

{
  "keys": ["apiKey", "timeout"],
  "results": [
    { "key": "apiKey", "value": "12345" },
    { "key": "timeout", "value": 30 }
  ]
}

Dependencies

  • Requires read/write access to the filesystem at the specified file path.
  • Uses Node.js built-in fs and path modules to manage files and directories.
  • No external APIs or services are required.
  • Ensure the n8n process has permission to create directories and write files at the configured path.

Troubleshooting

  • File parsing errors:
    If the JSON file is corrupted or contains invalid JSON, the node will throw an error indicating failure to parse the JSON file. To fix, ensure the file content is valid JSON or delete/reset the file.

  • Empty or missing keys:
    Operations requiring keys (get, set, delete) will fail if the key parameter is empty or missing. Always provide valid keys.

  • Mismatched keys and values on Set:
    When setting multiple keys and values, the number of keys must match the number of values. Otherwise, an error is thrown.

  • Invalid value types:
    Setting a value with an incorrect type (e.g., non-numeric string for a Number type) will cause an error. Make sure values conform to the selected type.

  • Permission issues:
    If the node cannot create directories or write to the file path, check filesystem permissions and ensure the path is accessible.

Links and References

Discussion