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:

  1. Open NodeBox and click New Automation
  2. Name your automation (e.g., "My First Workflow")
  3. Right-click on the canvas and select Add Node
  4. Create your first node and name it "Input Node"
  5. Click on the node and click Open to access the Node Editor
  6. Add the following code:
# Input Node - Generates a greeting message
message = "Hello from NodeBox!"
outputs['message'] = message
print(f"Output: {message}")
  1. Click Save and close the Node Editor
  2. Create a second node named "Display Node"
  3. 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}")
  1. Connect the output port of "Input Node" to the input port of "Display Node"
  2. Click Run to execute the automation
Expected Output:
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:

  1. Create a new automation named "File Reader Demo"
  2. Add a node and name it "File Path Input"
  3. 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}")
  1. Add a File Reader node (available in predefined nodes)
  2. Connect the output of "File Path Input" to the input of "File Reader"
  3. Add a third node named "Content Processor"
  4. 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")
  1. Connect the "File Reader" outputs to "Content Processor" inputs
  2. Run the automation to see the file statistics
Expected Output:
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}")
Expected Output:
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)}")
Note: Make sure Ollama is running with 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:

  1. Create a simple automation (e.g., a daily reminder or log generator)
  2. Save your automation with a meaningful name
  3. Navigate to the Scheduler tab in NodeBox
  4. Click New Schedule
  5. 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"
  6. Click Save Schedule
  7. 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')
Tip: You can view and manage all scheduled automations from the Scheduler tab. Use the toggle to enable/disable schedules without deleting them.

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 destination

Fan-Out Pattern

One Input → Multiple Processors

Send one piece of data to multiple nodes for parallel processing

Fan-In Pattern

Multiple Inputs → One Aggregator

Combine outputs from multiple nodes into a single result

Pipeline Pattern

Sequential Processing

Chain nodes in sequence where each step builds on the previous

Next Steps

Ready to build your own automations? Here's what to do next:

  • Explore the Code Reference for detailed API documentation
  • Check the FAQ for common questions and troubleshooting
  • Join the community on GitHub
  • Contribute your own examples and improvements!