### [n8n](https://github.com/n8n-io/n8n)

> Handle: `n8n`
> URL: [http://localhost:34191](http://localhost:34191)

`n8n` is a low-code workflow automation tool.

#### Starting

```bash
# [Optional] Pre-pull the images
harbor pull n8n

# Start the service
harbor up n8n

# [Optional] Open the web interface
harbor open n8n
```

When running for the first time, `n8n` will require you to set up an owner account. Follow the instructions on the web interface to complete the setup.

_Optionally_, you might import a sample workflow pre-configured to reach Harbor's built-in Ollama service. Note that it's identical to the [official Ollama example](https://n8n.io/workflows/2384-chat-with-local-llms-using-n8n-and-ollama/) with the only difference being pre-configured Ollama URL.

```bash
harbor run n8n n8n import:workflow --separate --input=/backup/workflows
harbor run n8n n8n import:credentials --separate --input=/backup/credentials
```

#### Usage

You can run arbitrary `n8n` CLI commands with `harbor run n8n`, for example:

```bash
harbor run n8n license:info
harbor run n8n audit
```

Apart from that, you'll be mainly interacting with `n8n` via its Web interface. You can import and export workflows, manage credentials, and more.

- [Official templates for AI workflows](https://n8n.io/workflows/categories/ai/)

#### Credentials configuration

When configuring credentials to access Harbor's services, please ensure to use "Internal" versions of the URLs. For example:
```bash
# "Internal" URL can be obtained with '-i' flag
harbor url -i ollama

# This won't work, as its outside of the Docker network
harbor url ollama
```

#### Configuration

See all configuration options with [`harbor config ls`](./3.-Harbor-CLI-Reference.md#harbor-config-list)

```bash
# All config options
harbor config ls | grep N8N
```

Notably, you can configure the location of the `n8n` workspace.

```bash
# Set the custom workspace location
harbor config set n8n.workspace ~/.n8n
```

Following mount structure (relative to the workspace) is used:
- `/storage` - Persistent storage for workflows and credentials
- `/backup` - Folder to import/export workflows and credentials
- `/shared` - Folder for shared files to be used with File nodes in `n8n`

##### Webhook URL

`n8n` often requires configuring `N8N_WEBHOOK_URL` environment variable for external access. Below is an example that'll work when it runs within Harbor's Docker network:

```bash
# Set the webhook URL
harbor env n8n N8N_WEBHOOK_URL http://localhost:$(harbor config get n8n.host.port)
```
