### Start n8n after Global Installation Source: https://docs.n8n.io/hosting/installation/npm/index Commands to run n8n after it has been installed globally using npm. Either 'n8n' or 'n8n start' can be used. ```bash n8n ``` ```bash n8n start ``` -------------------------------- ### Example: Get Binary Data for First Item Source: https://docs.n8n.io/code/cookbook/code-node/get-binary-data-buffer/index This example demonstrates how to get the binary data buffer for the first input item (index 0) using the default binary property name 'data'. ```javascript let binaryDataBufferItem = await this.helpers.getBinaryDataBuffer(0, 'data'); // Returns the data in the binary buffer for the first input item ``` -------------------------------- ### Install Project Dependencies Source: https://docs.n8n.io/integrations/creating-nodes/build/declarative-style-node/index Install the necessary project dependencies after setting up the node starter repository. ```bash npm i ``` -------------------------------- ### Start n8n Instance Source: https://docs.n8n.io/integrations/creating-nodes/test/run-node-locally/index Starts your local n8n instance from the command line. ```bash n8n start ``` -------------------------------- ### Start and Enable libvirt Service Source: https://docs.n8n.io/hosting/installation/server-setups/openshift-crc/index Start the libvirtd service and configure it to automatically start on system boot. This ensures the hypervisor is running and ready for CRC. ```bash sudo systemctl start libvirtd sudo systemctl enable libvirtd ``` -------------------------------- ### Conversational Agent Prompt Example Source: https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/conversational-agent/index Example of how to construct the prompt for the Conversational Agent, including tool descriptions, format instructions, and user input. This guides the agent's interaction and response format. ```text TOOLS ------ Assistant can ask the user to use tools to look up information that may be helpful in answering the user's original question. The tools the human can use are: {tools} {format_instructions} USER'S INPUT -------------------- Here is the user's input (remember to respond with a markdown code snippet of a JSON blob with a single action, and NOTHING else): {{input}} ``` -------------------------------- ### Start Webhook Processor (CLI) Source: https://docs.n8n.io/hosting/scaling/queue-mode/index Starts the n8n webhook processor using the command-line interface. Ensure you are in the root directory of your n8n installation. ```bash ./packages/cli/bin/n8n webhook ``` -------------------------------- ### Example Caddyfile Configuration Source: https://docs.n8n.io/hosting/installation/server-setups/digital-ocean/index An example of a Caddyfile configuration for the domain 'automate.example.com', proxying to the n8n service. ```nginx automate.example.com { reverse_proxy n8n:5678 { flush_interval -1 } } ``` -------------------------------- ### Start Cloudflared Tunnel and n8n Locally Source: https://docs.n8n.io/hosting/installation/npm/index Starts the cloudflared tunnel service for webhook accessibility and then runs n8n locally. Requires Docker and pnpm. This setup is for local development only. ```bash # Terminal 1: Start the cloudflared tunnel service pnpm --filter n8n-containers services --services cloudflared # Terminal 2: Start n8n locally pnpm dev ``` -------------------------------- ### Create Assistant: Example Description Source: https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-langchain.openai/assistant-operations/index Example of a description for a new assistant. Maximum length is 512 characters. ```text A virtual assistant that helps users with daily tasks, including setting reminders, answering general questions, and providing quick information. ``` -------------------------------- ### Subtitle Example Source: https://docs.n8n.io/integrations/creating-nodes/plan/node-ui-design/index Example of how to set a subtitle dynamically based on parameter values. ```javascript subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', ``` -------------------------------- ### Configure n8n Instance with Multiple Environment Variables Source: https://docs.n8n.io/hosting/configuration/settings-env-vars/index This example demonstrates setting up an n8n instance with all major configuration areas managed by environment variables. It includes instance owner, OIDC SSO, security policy, log streaming, MCP, and community package configurations. ```bash # Instance owner export N8N_INSTANCE_OWNER_MANAGED_BY_ENV=true export N8N_INSTANCE_OWNER_EMAIL= export N8N_INSTANCE_OWNER_FIRST_NAME= export N8N_INSTANCE_OWNER_LAST_NAME= export N8N_INSTANCE_OWNER_PASSWORD_HASH= # SSO using OIDC export N8N_SSO_MANAGED_BY_ENV=true export N8N_SSO_USER_ROLE_PROVISIONING=instance_role export N8N_SSO_OIDC_LOGIN_ENABLED=true export N8N_SSO_OIDC_CLIENT_ID= export N8N_SSO_OIDC_CLIENT_SECRET= export N8N_SSO_OIDC_DISCOVERY_ENDPOINT= # Security policy export N8N_SECURITY_POLICY_MANAGED_BY_ENV=true export N8N_MFA_ENFORCED_ENABLED=true export N8N_PERSONAL_SPACE_PUBLISHING_ENABLED=false export N8N_PERSONAL_SPACE_SHARING_ENABLED=false # Log streaming export N8N_LOG_STREAMING_MANAGED_BY_ENV=true export N8N_LOG_STREAMING_DESTINATIONS='[{"type":"webhook","url":"https://logs.example.com/n8n"}]' # MCP export N8N_MCP_MANAGED_BY_ENV=true export N8N_MCP_ACCESS_ENABLED=true # Community packages export N8N_COMMUNITY_PACKAGES_MANAGED_BY_ENV=true export N8N_COMMUNITY_PACKAGES='[{"name":"n8n-nodes-foo","version":"1.2.3"}]' ``` -------------------------------- ### Install libvirt Dependencies for CRC Setup Source: https://docs.n8n.io/hosting/installation/server-setups/openshift-crc/index Commands to install necessary libvirt dependencies on Debian/Ubuntu systems to resolve 'libvirt not found' errors during `crc setup`. ```bash sudo apt install -y qemu-kvm libvirt-daemon-system libvirt-clients sudo systemctl start libvirtd ``` -------------------------------- ### Create Custom Directory and Initialize npm Source: https://docs.n8n.io/integrations/creating-nodes/test/run-node-locally/index Manually creates the `custom` directory in `~/.n8n` and initializes npm within it if it doesn't exist. ```bash # In ~/.n8n directory run mkdir custom cd custom npm init ``` -------------------------------- ### Start n8n Worker Process Source: https://docs.n8n.io/hosting/scaling/queue-mode/index Starts a worker process for n8n. This command should be run from the root directory of your n8n installation. ```bash ./packages/cli/bin/n8n worker ``` -------------------------------- ### Install NetworkManager Source: https://docs.n8n.io/hosting/installation/server-setups/openshift-crc/index Install NetworkManager, which CRC requires for managing DNS entries for the cluster's internal domains. Start and enable the NetworkManager service. ```bash sudo apt install -y network-manager sudo systemctl start NetworkManager sudo systemctl enable NetworkManager ``` -------------------------------- ### Run CRC Setup Source: https://docs.n8n.io/hosting/installation/server-setups/openshift-crc/index Initializes CRC, configuring KVM networking, checking system requirements, and downloading the CRC bundle. This command only needs to be run once. ```bash crc setup ``` -------------------------------- ### Get Current Date Example Source: https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.datetime/index Demonstrates how to get the current date and time. Configure 'Include Current Time' and 'Output Field Name' parameters. ```javascript { "output": { "myOutputFieldName": "2023-10-27T10:30:00.000Z" } } ``` -------------------------------- ### Example URL with Query Parameters for Form Trigger Source: https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.formtrigger/index Demonstrates how to set initial field values in a form using query parameters and percent-encoding. This is only applicable for production URLs. ```url https://my-account.n8n.cloud/form/my-form?email=jane.doe%40example.com&name=Jane%20Doe ``` -------------------------------- ### Airtable Record Search Sorting Example Source: https://docs.n8n.io/integrations/creating-nodes/build/reference/ux-guidelines/index Example demonstrating how to add sorting options to a 'Get Many' operation, similar to the Airtable Record:Search node. ```typescript sort: [ { name: 'name', value: 'asc', } ] ``` -------------------------------- ### Try n8n with npx Source: https://docs.n8n.io/hosting/installation/npm/index Use this command to try n8n without a full installation. It downloads necessary components and allows immediate access via http://localhost:5678. ```bash npx n8n ``` -------------------------------- ### workflow.preExecute Source: https://docs.n8n.io/hosting/configuration/external-hooks/index Called before a workflow gets executed. Allows you to count or limit the number of workflow executions. Refer to Hook examples for an example using the `workflowContext` argument (only available from version 2.23.0). ```APIDOC ## workflow.preExecute ### Description Called before a workflow gets executed. Allows you to count or limit the number of workflow executions. Refer to Hook examples for an example using the `workflowContext` argument (only available from version 2.23.0). ### Parameters #### Path Parameters - **workflow** (Workflow) - Required - The workflow object. - **mode** (WorkflowExecuteMode) - Required - The execution mode. - **workflowContext** (WorkflowHookContextService) - Required - The workflow context service (available from version 2.23.0). ### Response #### Success Response This hook does not return a value. ``` -------------------------------- ### Complete Log Streaming Configuration Source: https://docs.n8n.io/log-streaming/index A comprehensive example demonstrating how to configure log streaming using environment variables. This includes setting up both webhook and Sentry destinations with various options. ```bash N8N_LOG_STREAMING_MANAGED_BY_ENV=true N8N_LOG_STREAMING_DESTINATIONS='[ { "type": "webhook", "label": "Ops webhook", "enabled": true, "subscribedEvents": ["n8n.workflow", "n8n.audit"], "anonymizeAuditMessages": true, "url": "https://hooks.example.com/n8n", "method": "POST", "sendHeaders": true, "specifyHeaders": "keypair", "headerParameters": { "parameters": [ { "name": "Authorization", "value": "Bearer s3cret" } ] }, "circuitBreaker": { "maxFailures": 5, "failureWindow": 60000 } }, { "type": "sentry", "label": "Sentry prod", "subscribedEvents": ["n8n.workflow"], "dsn": "https://public@sentry.example.com/1" } ]' ``` -------------------------------- ### Get Workflows with Pagination Source: https://docs.n8n.io/api/pagination/index This example demonstrates how to retrieve a paginated list of active workflows, specifying a limit of 150 results per page. It shows how to get the first page and then how to use the `nextCursor` from the response to fetch subsequent pages. ```APIDOC ## GET /workflows ### Description Retrieves a paginated list of active workflows. ### Method GET ### Endpoint `/api/v/workflows` ### Parameters #### Query Parameters - **active** (boolean) - Optional - Filters for active workflows. - **limit** (integer) - Optional - The number of results to return per page. Maximum is 250. - **cursor** (string) - Optional - A cursor to retrieve the next page of results. ### Request Example ``` # For a self-hosted n8n instance curl -X 'GET' \ '://api/v/workflows?active=true&limit=150' \ -H 'accept: application/json' \ -H 'X-N8N-API-KEY: ' # For n8n Cloud curl -X 'GET' \ '/api/v/workflows?active=true&limit=150' \ -H 'accept: application/json' \ -H 'X-N8N-API-KEY: ' ``` ### Response #### Success Response (200) - **data** (array) - An array of workflow objects. - **nextCursor** (string) - A cursor to retrieve the next page of results. Present if there are more pages. #### Response Example ```json { "data": [ // Workflow data objects ], "nextCursor": "MTIzZTQ1NjctZTg5Yi0xMmQzLWE0NTYtNDI2NjE0MTc0MDA" } ``` ### Requesting the Next Page To request the next page, append the `cursor` query parameter with the value of `nextCursor` from the previous response. ``` # For a self-hosted n8n instance curl -X 'GET' \ '://api/v/workflows?active=true&limit=150&cursor=MTIzZTQ1NjctZTg5Yi0xMmQzLWE0NTYtNDI2NjE0MTc0MDA' \ -H 'accept: application/json' # For n8n Cloud curl -X 'GET' \ '/api/v/workflows?active=true&limit=150&cursor=MTIzZTQ1NjctZTg5Yi0xMmQzLWE0NTYtNDI2NjE0MTc0MDA' \ -H 'accept: application/json' ``` ``` -------------------------------- ### Create and Navigate to Nodes Directory Source: https://docs.n8n.io/integrations/community-nodes/installation/manual-install/index Create the `~/.n8n/nodes` directory if it does not exist and then navigate into it. This directory is used for manual node installations. ```bash mkdir ~/.n8n/nodes cd ~/.n8n/nodes ``` -------------------------------- ### Chat Trigger Node Setup Source: https://docs.n8n.io/advanced-ai/intro-tutorial/index This workflow starts with a Chat Trigger node, allowing text input to initiate the workflow. In production, it can be connected to public chat interfaces. ```json { "name": "Chat Trigger", "type": "trigger", "id": "f1a2b3c4d5e6f7g8h9i0", "parameters": { "chatMode": true } } ``` -------------------------------- ### Resource and Operation Parameter Setup Source: https://docs.n8n.io/integrations/creating-nodes/build/reference/code-standards/index Demonstrates how to set up 'Resource' and 'Operation' parameters in a node's properties. Use 'displayOptions' to conditionally show operations based on the selected resource. ```typescript export const ExampleNode implements INodeType { description: { displayName: 'Example Node', ... properties: [ { displayName: 'Resource', name: 'resource', type: 'options', options: [ { name: 'Resource One', value: 'resourceOne' }, { name: 'Resource Two', value: 'resourceTwo' } ], default: 'resourceOne' }, { displayName: 'Operation', name: 'operation', type: 'options', // Only show these operations for Resource One displayOptions: { show: { resource: [ 'resourceOne' ] } }, options: [ { name: 'Create', value: 'create', description: 'Create an instance of Resource One' } ] } ] } } ``` -------------------------------- ### Create Assistant: Example Instructions Source: https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-langchain.openai/assistant-operations/index Example of system instructions for an assistant, defining its persona and response style. Maximum length is 32,768 characters. ```text Always respond in a friendly and engaging manner. When a user asks a question, provide a concise answer first, followed by a brief explanation or additional context if necessary. If the question is open-ended, offer a suggestion or ask a clarifying question to guide the conversation. Keep the tone positive and supportive, and avoid technical jargon unless specifically requested by the user. ``` -------------------------------- ### Add Bitnami Helm Repository Source: https://docs.n8n.io/hosting/installation/server-setups/openshift-crc/index Adds the Bitnami Helm chart repository to the local Helm configuration and updates the repository index. This is a one-time setup step required to install Bitnami charts. ```bash helm repo add bitnami https://charts.bitnami.com/bitnami helm repo update ``` -------------------------------- ### Build and Link Your Node Locally Source: https://docs.n8n.io/integrations/creating-nodes/test/run-node-locally/index Builds your node project and links it for local development. ```bash # In your node directory npm run build npm link ``` -------------------------------- ### Weaviate Search Filter Example Source: https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.vectorstoreweaviate/index Demonstrates how to construct a search filter for Weaviate, using OR logic to match documents from specific sources. This filter can be used with operations like 'Get Many' or 'Retrieve Documents'. ```json { "OR": [ { "path": ["source"], "operator": "Equal", "valueString": "source1" }, { "path": ["source"], "operator": "Equal", "valueString": "source1" } ] } ``` -------------------------------- ### AWS IAM Role Trust Policy Example Source: https://docs.n8n.io/integrations/builtin/credentials/aws/index This JSON defines the trust policy for an IAM role, specifying which principals are allowed to assume it and under what conditions. Ensure the 'Principal' and 'Condition' match your n8n setup. ```json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::SOURCE-ACCOUNT:root" }, "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "sts:ExternalId": "your-unique-external-id" } } } ] } ``` -------------------------------- ### Get Index of First Matching Element Source: https://docs.n8n.io/data/expression-reference/array/index The `Array.indexOf()` method returns the index of the first occurrence of a specified element in an array. It returns -1 if the element is not found. An optional `start` parameter can specify the search index. ```javascript // names = ["Bob", "Bill", "Nat"]; names.indexOf("Nat") //=> 2 ``` -------------------------------- ### Generic Authentication Setup for Node Creators Source: https://docs.n8n.io/release-notes/0-x/index Example of the new generic authentication syntax for node creators. Use this for authentication methods where data is sent in the header, body, or query string, but not for complex methods like OAuth. ```typescript import { IAuthenticateGeneric, ICredentialType, INodeProperties, } from 'n8n-workflow'; export class AsanaApi implements ICredentialType { name = 'asanaApi'; displayName = 'Asana API'; documentationUrl = 'asana'; properties: INodeProperties[] = [ { displayName: 'Access Token', name: 'accessToken', type: 'string', default: '', }, ]; authenticate: IAuthenticateGeneric = { type: 'generic', properties: { headers: { Authorization: '=Bearer {{$credentials.accessToken}}', }, }, }; } ``` -------------------------------- ### Configure loadOptions for Dynamic Parameters Source: https://docs.n8n.io/integrations/creating-nodes/build/reference/node-base-files/declarative-style-parameters/index Use `loadOptions` within `methods` to query services for user-specific settings. This example shows how to define routing and output settings for handling returned options, including data transformation and sorting. ```javascript methods : { loadOptions: { routing: { request: { url: '/webhook/example-option-parameters', method: 'GET', }, output: { postReceive: [ { // When the returned data is nested under another property // Specify that property key type: 'rootProperty', properties: { property: 'responseData', }, }, { type: 'setKeyValue', properties: { name: '={{$responseItem.key}} ({{$responseItem.value}}) ', value: '={{$responseItem.value}}', }, }, { // If incoming data is an array of objects, sort alphabetically by key type: 'sort', properties: { key: 'name', }, }, ] } } } }, ``` -------------------------------- ### Install Helm Source: https://docs.n8n.io/hosting/installation/server-setups/openshift-crc/index Installs Helm version 3 using the official installation script. ```bash curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash ``` -------------------------------- ### Install n8n Globally with npm Source: https://docs.n8n.io/hosting/installation/npm/index Installs the latest stable version of n8n globally on your system. This command is used for a standard installation. ```bash npm install n8n -g ``` -------------------------------- ### Install Redis using Helm Source: https://docs.n8n.io/hosting/installation/server-setups/openshift-crc/index Installs Redis using the Bitnami Helm chart in standalone architecture. Ensures security context adaptation for OpenShift. ```bash helm install redis bitnami/redis \ --namespace $NAMESPACE \ --set auth.enabled=false \ --set architecture=standalone \ --set global.compatibility.openshift.adaptSecurityContext=auto \ --wait ``` -------------------------------- ### Install Docker Compose Source: https://docs.n8n.io/hosting/installation/server-setups/hetzner/index Installs Docker Compose plugin on the Hetzner server. This is required as the Docker app image does not include it by default. ```bash apt update && apt -y upgrade apt install docker-compose-plugin ```