NodeBox Examples
Learn NodeBox by exploring real-world examples! Each example demonstrates key features and workflows to help you build powerful automations.
Example 1: Basic Node Connection
This example shows how to create a simple automation with two nodes: a text input node that outputs data, and a display node that receives and processes that data.
Step-by-Step Guide:
- Open NodeBox and click New Automation
- Name your automation (e.g., "My First Workflow")
- Right-click on the canvas and select Add Node
- Create your first node and name it "Input Node"
- Click on the node and click Open to access the Node Editor
- Add the following code:
# Input Node - Generates a greeting message
message = "Hello from NodeBox!"
outputs['message'] = message
print(f"Output: {message}")
- Click Save and close the Node Editor
- Create a second node named "Display Node"
- Add this code to the Display Node:
# Display Node - Receives and processes the message
received_message = inputs.get('message', 'No message received')
outputs['result'] = f"Processed: {received_message}"
print(f"Received: {received_message}")
- Connect the output port of "Input Node" to the input port of "Display Node"
- Click Run to execute the automation
Output: Hello from NodeBox! Received: Hello from NodeBox!
Example 2: File Handling with File Reader Node
This example demonstrates how to use the built-in File Reader node to read a text file and process its contents.
Prerequisites:
- Create a text file at
/path/to/sample.txt
with some content - Example content: "This is a sample text file for NodeBox automation."
Step-by-Step Guide:
- Create a new automation named "File Reader Demo"
- Add a node and name it "File Path Input"
- Add this code to provide the file path:
# File Path Input Node
file_path = "/path/to/sample.txt" # Update with your file path
outputs['file_path'] = file_path
print(f"File path set to: {file_path}")
- Add a File Reader node (available in predefined nodes)
- Connect the output of "File Path Input" to the input of "File Reader"
- Add a third node named "Content Processor"
- Add this code to process the file content:
# Content Processor Node
content = inputs.get('content', '')
error = inputs.get('error', None)
if error:
print(f"Error: {error}")
outputs['result'] = f"Failed: {error}"
else:
word_count = len(content.split())
char_count = len(content)
outputs['result'] = f"File read successfully!\nWords: {word_count}\nCharacters: {char_count}"
print(f"File contains {word_count} words and {char_count} characters")
- Connect the "File Reader" outputs to "Content Processor" inputs
- Run the automation to see the file statistics
File path set to: /path/to/sample.txt Successfully read file: /path/to/sample.txt File contains 9 words and 55 characters
Example 3: Data Transformation Pipeline
Build a multi-node pipeline that processes data through several transformation steps. This demonstrates how to chain multiple nodes together for complex workflows.
Workflow Overview:
Data Generator → Filter Node → Transform Node → Output Node
Node 1: Data Generator
# Data Generator Node - Creates a list of numbers
data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
outputs['numbers'] = data
print(f"Generated data: {data}")
Node 2: Filter Node
# Filter Node - Keeps only even numbers
numbers = inputs.get('numbers', [])
filtered = [n for n in numbers if n % 2 == 0]
outputs['filtered_numbers'] = filtered
print(f"Filtered to even numbers: {filtered}")
Node 3: Transform Node
# Transform Node - Squares each number
numbers = inputs.get('filtered_numbers', [])
squared = [n ** 2 for n in numbers]
outputs['transformed'] = squared
print(f"Squared numbers: {squared}")
Node 4: Output Node
# Output Node - Calculates the sum
numbers = inputs.get('transformed', [])
total = sum(numbers)
outputs['final_result'] = total
print(f"Final sum: {total}")
print(f"Result of pipeline: {numbers} → Sum = {total}")
Generated data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Filtered to even numbers: [2, 4, 6, 8, 10] Squared numbers: [4, 16, 36, 64, 100] Final sum: 220 Result of pipeline: [4, 16, 36, 64, 100] → Sum = 220
Example 4: AI Integration with Ollama
Integrate local AI models using Ollama. This example shows how to send a prompt to an AI model and process the response.
Prerequisites:
- Ollama installed and running (
ollama serve
) - A model downloaded (e.g.,
ollama pull llama2
)
Node 1: Prompt Generator
# Prompt Generator Node
prompt = "Explain what NodeBox is in one sentence."
outputs['prompt'] = prompt
print(f"Sending prompt: {prompt}")
Node 2: Ollama API Call
# Ollama API Node
import requests
import json
prompt = inputs.get('prompt', '')
try:
response = requests.post(
'http://localhost:11434/api/generate',
json={
'model': 'llama2',
'prompt': prompt,
'stream': False
}
)
if response.status_code == 200:
result = response.json()
ai_response = result.get('response', '')
outputs['ai_response'] = ai_response
print(f"AI Response: {ai_response}")
else:
outputs['ai_response'] = f"Error: {response.status_code}"
print(f"API Error: {response.status_code}")
except Exception as e:
outputs['ai_response'] = f"Exception: {str(e)}"
print(f"Error calling Ollama: {str(e)}")
ollama serve
before executing this automation.
Example 5: Scheduled Automation
Learn how to schedule automations to run at specific times or intervals using NodeBox's built-in scheduler.
Step-by-Step Guide:
- Create a simple automation (e.g., a daily reminder or log generator)
- Save your automation with a meaningful name
- Navigate to the Scheduler tab in NodeBox
- Click New Schedule
- Configure the schedule:
- Automation: Select your saved automation
- Schedule Type: Choose "Interval" or "Cron"
- Interval: e.g., "Every 1 hour" or "Every day at 9:00 AM"
- Click Save Schedule
- Your automation will now run automatically based on the schedule
Example: Daily Log Generator
# Daily Log Node
import datetime
current_time = datetime.datetime.now()
log_message = f"Daily log generated at {current_time.strftime('%Y-%m-%d %H:%M:%S')}"
outputs['log'] = log_message
print(log_message)
# Optional: Save to file
with open('automation_log.txt', 'a') as f:
f.write(log_message + '\n')
Tips & Best Practices
Save Often
Always save your automations before running them. Use descriptive names to easily identify workflows later.
Debugging Nodes
Use print()
statements liberally in your node code.
The output will appear in the console and help you trace data flow.
Port Naming
Give your input and output ports meaningful names. This makes it easier to understand connections when workflows get complex.
Modular Design
Break complex tasks into smaller, reusable nodes. This makes debugging easier and allows you to reuse nodes across different automations.
Error Handling
Always include try-except blocks when working with external resources (files, APIs, etc.) to handle errors gracefully.
File Paths
Use absolute paths for file operations to avoid confusion. Supported formats: .txt, .json, .csv, and more.
Common Automation Patterns
ETL Pattern
Extract → Transform → Load
Read data from a source, process it, and save to a destinationFan-Out Pattern
One Input → Multiple Processors
Send one piece of data to multiple nodes for parallel processingFan-In Pattern
Multiple Inputs → One Aggregator
Combine outputs from multiple nodes into a single resultPipeline Pattern
Sequential Processing
Chain nodes in sequence where each step builds on the previous