In this video, I’ll show you how to automate nearly anything with n8n, a powerful self-hosted, low-code automation platform. We’ll explore how to install it, connect various services, and build advanced workflows using data transformation and JavaScript expressions, including automating social media posting from Notion.
References#
- n8n Official Website: https://n8n.io/
- Docker Tutorial: https://www.youtube.com/watch?v=Nm1tfmZDqo8
- Traefik Tutorial: https://www.youtube.com/watch?v=-hfejNXqOzA
Notes#
n8n Installation with Docker#
n8n recommends using Docker for self-hosting, ensuring a clean and isolated environment.
Here’s a basic docker compose.yaml
configuration to get you started:
---
services:
n8n:
image: n8nio/n8n:1.110.1
container_name: n8n-test-1
environment:
- N8N_LOG_LEVEL=info
- GENERIC_TIMEZONE=Europe/Berlin
- TZ=Europe/Berlin
- N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
- N8N_RUNNERS_ENABLED=true
- N8N_SECURE_COOKIE=false # Needed when NOT using HTTPS (traefik)
# important when using traefik
- N8N_EDITOR_BASE_URL=http://n8n-test-1.orb.local:5678
# enable postgres
# - DB_TYPE=postgresdb
# - DB_POSTGRESDB_HOST=postgres
# - DB_POSTGRESDB_PORT=${DB_POSTGRESDB_PORT:-5432}
# - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
# - DB_POSTGRESDB_USER=${POSTGRES_USER}
# - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- /etc/localtime:/etc/localtime:ro
- data:/home/node/.n8n
ports:
- "5678:5678"
# networks:
# - proxy
# labels:
# - "traefik.enable=true"
# - "traefik.http.routers.n8n.rule=Host(`http://n8n-test-1.orb.local:5678`)"
# - "traefik.http.routers.n8n.entrypoints=websecure"
# - "traefik.http.routers.n8n.tls=true"
# - "traefik.http.routers.n8n.tls.certresolver=${TRAEFIK_CERTRESOLVER:-le}"
# - "traefik.http.services.n8n.loadbalancer.server.port=${N8N_PORT:-5678}"
restart: unless-stopped
volumes:
data:
driver: local
# networks:
# proxy:
# external: true
Understanding Workflows#
- Initial Setup: After installation, configure your account (email, name, password) and customize n8n settings. You can get paid features for free forever on your self-hosted instance.
- Workflow Basics:
- Workflows process data from left (input) to right (output).
- Green colored nodes indicate successful execution.
- The Execution Log on the main page provides detailed information about each run.
- Templates: Explore the extensive library of pre-built templates to kickstart your automation.
Triggers#
Triggers initiate your workflows and can be configured in various ways:
- On App Events: Execute when something specific happens in an integrated application (e.g., a Notion page is updated, a GitLab Merge Request or Issue is created).
- On Schedule: Run the workflow at specified intervals (e.g., every X seconds, minutes, hours, days) or at a particular timestamp.
- On Webhook Call: A webhook is an HTTP request sent from one system to another based on an event, allowing real-time data transfer and action processing.
Actions#
Actions are the core building blocks of your workflows, performing tasks or manipulating data:
- AI Integrations: Connect with AI agents or APIs like OpenAI and Gemini.
- App Integrations: Leverage over 1,100 integrations with various platforms across Cybersecurity, Data & Storage, Development, and Social Media.
- Data Transformation: Add, remove, or combine items, and convert data between different formats.
- Flows: Implement logical operations within your workflow.
- Core Functions: Execute commands, send webhooks to other platforms, and more.
- Human Confirmation: Integrate a step to wait for human confirmation via messaging platforms or email.
Managing Credentials#
To connect to different applications, you need to authenticate using credentials. While some integrations are straightforward (e.g., Discord), others, particularly those using OAuth, can be more complex.
- OAuth Callback URLs: The callback URL is where the authenticated provider sends its response. This should typically be your local n8n instance’s address, as it doesn’t require external access.
Leveraging JavaScript Expressions#
JavaScript expressions are invaluable for filtering specific items, retrieving data from previous nodes, and performing custom logic.
- Syntax: Use double curly braces
{{ JavaScript Expression }}
. - n8n’s Templating Language: n8n uses a templating language called Tournament, extended with custom methods, variables, and data transformation functions.
- Example: Use
{{ DateTime.now() }}
to get the current timestamp.
Advanced Flow & Data Transformation#
- Split Out Node: Select a property to split out and make sure to include “All Other Fields” to retain necessary data for further transformations.
- If Node: Use for simple conditional (if/else) logic.
- Switch Node: Create routing rules for different cases, allowing you to change output names and convert data types as required. An example use case is routing social media posts based on the platform, such as splitting out “Discord” posts to send via a webhook.
Error Handling#
Implement error handling within your workflows to manage unexpected issues gracefully. Remember to activate workflows when they are scheduled to run.