persistent-variables

n8n community node for storing global variables in SQLite database

Package Information

Released: 13 mo ago
Downloads: 1 weekly / 30 monthly
Latest Version: 1.0.0
Author: StancuFlorin

Documentation

n8n Persistent Variables Node

A community node for n8n that allows you to store and retrieve persistent variables in a SQLite database. These variables can be shared across multiple workflows and persist between n8n restarts.

Features

  • Set Variable: Store a variable with a name and value
  • Get Variable: Retrieve a variable value by name
  • SQLite Storage: Variables are stored in a local SQLite database
  • Persistent: Variables persist between n8n restarts
  • Cross-Workflow: Variables can be accessed from any workflow

Installation

Using n8n UI (Recommended)

  1. Open your n8n instance and go to Settings → Community Nodes

  2. Click "Install a community node"

  3. Enter the package name:

    n8n-nodes-persistent-variables
    
  4. Click "Install" and wait for the installation to complete

  5. Restart n8n if prompted

  6. Find the node in the node panel under the "Transform" category

Manual Installation (Advanced Users)

If you prefer manual installation or are developing the node:

# Clone the repository
git clone https://github.com/StancuFlorin/n8n-nodes-persistent-variables.git
cd n8n-nodes-persistent-variables

# Install dependencies
npm install

# Build the node
npm run build

# Copy to your n8n custom nodes directory
cp -r nodes /path/to/your/n8n/custom/nodes/

Usage

Setting a Variable

  1. Add the "Global Variables" node to your workflow
  2. Set the operation to "Set Variable"
  3. Enter the variable name (e.g., "apiKey")
  4. Enter the variable value (e.g., "your-api-key-here")
  5. Optionally specify a custom database path (default: ./global_variables.db)

Getting a Variable

  1. Add the "Global Variables" node to your workflow
  2. Set the operation to "Get Variable"
  3. Enter the variable name to retrieve
  4. Optionally specify a custom database path (default: ./global_variables.db)

Node Parameters

Parameter Type Required Description
Operation Options Yes Choose between "Set Variable" or "Get Variable"
Variable Name String Yes Name of the variable to set or get
Variable Value String No Value to set (only for Set operation)
Database Path String Yes Path to the SQLite database file

Output Format

Set Variable Output

{
  "operation": "set",
  "variableName": "myVariable",
  "result": {
    "message": "Variable 'myVariable' set successfully",
    "name": "myVariable",
    "value": "myValue",
    "changes": 1
  },
  "success": true
}

Get Variable Output

{
  "operation": "get",
  "variableName": "myVariable",
  "result": {
    "message": "Variable 'myVariable' retrieved successfully",
    "name": "myVariable",
    "value": "myValue",
    "created_at": "2024-01-01 12:00:00",
    "updated_at": "2024-01-01 12:00:00",
    "exists": true
  },
  "success": true
}

Use Cases

  • Configuration Management: Store API keys, endpoints, or other configuration values
  • Data Caching: Cache expensive computation results between workflow runs
  • State Management: Maintain state information across different workflows
  • User Preferences: Store user-specific settings or preferences
  • Cross-Workflow Communication: Share data between different workflows

Database Schema

The node creates a SQLite table with the following structure:

CREATE TABLE global_variables (
    name TEXT PRIMARY KEY,
    value TEXT NOT NULL,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

Development

Prerequisites

  • Node.js 16+
  • npm or yarn
  • TypeScript

Building

# Install dependencies
npm install

# Build the project
npm run build

# Watch for changes during development
npm run dev

Linting

# Run linter
npm run lint

# Fix linting issues
npm run lintfix

Testing

The node includes error handling and will return error information in the output if something goes wrong. You can test the node by:

  1. Setting a variable with the "Set Variable" operation
  2. Retrieving the same variable with the "Get Variable" operation
  3. Checking the output to ensure the values match

Error Handling

The node includes comprehensive error handling:

  • Database connection errors
  • SQL execution errors
  • Missing variable errors (for Get operation)
  • File system errors (database path issues)

Errors are returned in the output with success: false and an error message.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Support

For issues and feature requests, please use the GitHub issue tracker.

Changelog

1.0.0

  • Initial release
  • Set and Get variable operations
  • SQLite database storage
  • Cross-workflow variable sharing

Discussion