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 users to get, set, delete individual variables by key, list all variables, or delete all variables at once. This is useful for workflows that need persistent storage of configuration or state data outside of n8n's built-in credentials or environment variables.

Common scenarios include:

  • Storing API tokens or configuration values that multiple workflows can access.
  • Persisting counters or flags that track workflow progress across executions.
  • Managing feature toggles or dynamic settings without redeploying workflows.

For example, you could use this node to store a daily API request count and increment it each time a workflow runs, or to save user preferences that affect workflow behavior.

Properties

Name Meaning
Key(Separate Multiple Items with Commas in English) The key(s) of the variable(s) to get, set, or delete. Multiple keys can be separated by commas.
File Path The path to the JSON file where variables are saved and loaded from. Defaults to ~/.n8n/global_variables.json.

Note: The "Key" property is required for operations get, set, and delete.

Output

The node outputs a JSON object describing the result of the operation:

  • For Get:

    {
      "action": "get",
      "keys": ["key1", "key2"],
      "results": [
        {"key": "key1", "value": <value_or_null>},
        {"key": "key2", "value": <value_or_null>}
      ]
    }
    

    Each requested key returns its value or null if not found.

  • For Set:

    {
      "action": "set",
      "keys": ["key1", "key2"],
      "success": true
    }
    

    Indicates which keys were set successfully.

  • For Delete:

    {
      "action": "delete",
      "deleted": ["key1", "key3"],
      "notFound": ["key2"]
    }
    

    Lists keys deleted and keys that were not found.

  • For List ALL:

    {
      "action": "list",
      "variables": {
        "key1": <value>,
        "key2": <value>,
        ...
      }
    }
    

    Returns all stored variables as key-value pairs.

  • For Delete All:

    {
      "action": "delete_all"
    }
    

    Confirms all variables were deleted.

The node does not output binary data.

Dependencies

  • Requires read/write access to the specified JSON file path on the local filesystem.
  • Uses Node.js fs and path modules to manage files and directories.
  • No external APIs or services are required.
  • The file path can be customized; ensure the directory exists or can be created by the node.

Troubleshooting

  • JSON Parsing Errors:
    If the JSON file is corrupted or contains invalid JSON, the node will throw an error indicating failure to parse the file. To fix, manually correct or delete the JSON file.

  • Missing Keys:
    When getting or deleting variables, if keys are empty or missing, the node throws an error requiring non-empty keys.

  • Mismatched Key and Value Counts (Set Operation):
    When setting multiple keys and values, the counts must match exactly. Otherwise, an error is thrown.

  • Invalid Value Types:
    When setting values, the node validates the type (string, number, boolean, object, array). Invalid conversions or malformed JSON for objects/arrays cause errors.

  • File System Permissions:
    Ensure the node has permission to create directories and write to the specified file path. Lack of permissions will cause failures.

Links and References

Discussion