if I want to store key value data for n8n other workflow to use but dont have access to redis what can I do
Assistant
If you want to store key-value data for use across multiple n8n workflows but don't have access to Redis or other external key-value stores, here are some alternative approaches you can consider:
User
how can I save a json file on the server so that another workflow can use it
Assistant
To save a JSON file on the server from one n8n workflow and then read it in another workflow, you can use the and nodes. Here's a step-by-step guide:
User
help me adjust this code so that each item generated has a key, one that says description and anoter one that says content:
const input = $json.graph; // access the 'graph' array inside the first item
// Return two outputs: one with descriptions, one with decodedContents
return [
{ json: descriptions },
{ json: decodedContents }
];
Assistant
Certainly! To adjust your code so that each item generated has two keys: description and content, and each item corresponds to an entry from your input, you can transform the input array into an array of objects where each object has these two properties.
Assuming you want to return an array of items like:
Environment Variables: You can set environment variables on the server where n8n runs, and access them in workflows using the Set node or Function nodes. However, these are static and not meant for dynamic data storage.
Workflow or Global Variables: n8n doesn't have true global variables that persist across workflows, but you can pass data between workflows using webhooks or execution data.
2. Use n8n's Internal Database (SQLite/Postgres)
n8n stores its own data in a database (SQLite by default). You can create a custom table in the same database to store key-value pairs.
Use the Execute Query node to insert, update, or retrieve data from this table.
This requires some SQL knowledge and access to the database.
3. Use Files for Storage
Store key-value pairs in a JSON file on the server.
Use the Read Binary File and Write Binary File nodes to read/write JSON data.
Use a Function node to parse and update the JSON content.
This works but is less efficient and can have concurrency issues.
4. Use External Services with Free Tiers or APIs
If Redis is not available, consider alternative free or easily accessible services:
Google Sheets: Use it as a key-value store by storing keys in one column and values in another.
Airtable: Similar to Google Sheets, with API access.
Firebase Realtime Database or Firestore: Provides key-value style data storage with free tiers.
Use the respective n8n nodes or HTTP Request nodes to interact with these services.
5. Trigger Workflows with Data Passing
Instead of storing data globally, pass data between workflows directly using:
Webhook nodes to trigger workflows with data payloads.
HTTP Request nodes to call other workflows and pass data.
Summary Recommendation
If you want a simple, no-external dependency method, using a JSON file or the internal database with SQL queries is a good start. For more scalable and robust solutions, consider Google Sheets or Airtable as a key-value store.
If you want, I can help you with example workflows or code snippets for any of these methods!
Write Binary File
Read Binary File
Workflow 1: Save JSON Data to a File
Prepare JSON Data
Use a Set node or Function node to create the JSON data you want to save.
Example using a Set node:
Add a field, e.g. data, and paste your JSON object (it will be treated as a string).