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 individual keys, list all variables, or delete all variables from the 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 between different workflow executions or nodes.

Practical examples:

  • Storing API tokens or configuration flags that multiple workflows can access.
  • Keeping counters or state information that persists across workflow runs.
  • Clearing all stored variables when resetting an environment or starting fresh.

Properties

Name Meaning
File Path File path for saving variables as a string. Example: ~/.n8n/global_variables.json

Note: For this "Delete All" operation, only the "File Path" property is relevant.

Output

The output JSON contains a single field:

  • json: An object with no keys (an empty object {}) after deleting all variables from the JSON file.

In other words, after the "Delete All" operation, the JSON file is overwritten with an empty JSON object {}, and the node outputs an empty object indicating success.

No binary data is produced by this node.

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 credentials are required.

Troubleshooting

  • File path issues: If the directory does not exist, it will be created automatically. However, if the process lacks permissions to create directories or write files at the specified location, errors will occur.
  • JSON parsing errors: If the existing JSON file is corrupted or contains invalid JSON, the node will throw an error indicating failure to parse the JSON file.
  • Unknown operation: If an unsupported operation value is provided, the node throws an error stating "Unknown action".
  • General file write errors: Insufficient permissions or locked files may cause write failures.

To resolve these:

  • Ensure the file path is correct and writable by the n8n process.
  • Verify the JSON file content is valid JSON or delete/replace it if corrupted.
  • Use only supported operations as defined by the node.

Links and References

Discussion