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, 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 across executions without relying on external databases or services.

Common scenarios include:

  • Storing configuration values or flags that multiple workflows can access.
  • Persisting counters or state information between workflow runs.
  • Managing environment-like variables locally within n8n.

For example, you could use this node to set a variable "lastRunTime" with the current timestamp and later retrieve it to decide if a workflow should proceed.

Properties

Name Meaning
Operation The action to perform: Get, Set, Delete, List ALL, or Delete All variables
Key(Separate Multiple Items with Commas in English) The key(s) of the variable(s) to get, set, or delete. Multiple keys separated by commas.
Value The value to set for the given key(s). When setting multiple keys, separate values by commas.
Type The data type of the value(s) when setting: String, Number, Boolean, Object, or Array
File Path The path to the JSON file where variables are stored (e.g., ~/.n8n/global_variables.json)

Output

The output JSON structure varies depending on the operation:

  • Get: Returns an array of objects with each containing a key and its corresponding value (or null if not found).
  • Set: Returns the keys set and a success flag.
  • Delete: Returns arrays of deleted keys and keys not found.
  • List ALL: Returns all variables as a JSON object.
  • Delete All: No specific output other than clearing all variables.

No binary data is output by this node.

Example output for a "get" operation:

{
  "keys": ["exampleKey"],
  "results": [
    {
      "key": "exampleKey",
      "value": "exampleValue"
    }
  ]
}

Dependencies

  • Requires read/write access to the filesystem at the specified file path.
  • Uses Node.js built-in fs and path modules.
  • No external API or service dependencies.
  • The file path must be accessible and writable by the n8n process.

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 JSON file. Fix by correcting the JSON format or deleting the file to start fresh.
  • Empty Key Errors: For operations requiring keys (get, set, delete), providing empty or missing keys will cause errors.
  • Mismatched Keys and Values: When setting multiple keys and values, the counts must match exactly; otherwise, an error is thrown.
  • Invalid Value Types: Setting values with incorrect types (e.g., non-numeric string for number type, invalid JSON for object/array) will cause parsing errors.
  • File Access Issues: If the directory does not exist, it will be created automatically. However, permission issues may prevent reading/writing the file.
  • Unsupported Operations: Using an unknown operation value will result in an error.

Links and References

Discussion