Managing API keys and sensitive identifiers securely is a cornerstone of good automation hygiene. When self-hosting n8n on Hostinger, using environment variables ensures your workflows remain portable, secure, and easy to maintain.

In this guide, we’ll walk through how to define and use environment variables—like TELEGRAM_CHAT_ID—inside n8n workflows, especially when integrating with nodes like Telegram.

Why Use Environment Variables

Hardcoding values like API keys or chat IDs directly into nodes can expose sensitive data when exporting or sharing workflows. Instead, use environment variables to:

  • Keep secrets out of your workflow JSON
  • Enable easy updates without editing workflows
  • Improve portability across environments

Example:
Instead of hardcoding a Telegram Chat ID, use:

{{ $env.TELEGRAM_CHAT_ID }}

This masks the actual value and resolves it dynamically at runtime.

How to Define Environment Variables in Hostinger

If you’re using Hostinger’s Docker Manager to run n8n, follow these steps:

1. Open Docker Manager

  • Navigate to your n8n container
  • Click the Manage button

2. Edit the .yaml Configuration

  • Select the .yaml editor
  • Locate the section where existing environment variables are defined
  • Add your new variable after the current ones, preserving indentation and formatting:

environment: - TELEGRAM_CHAT_ID=12345678

Important: YAML is sensitive to tabs and spaces. Make sure formatting matches existing entries.

3. Deploy the Changes

  • Click the Deploy button (top right corner)
  • This will restart the container with the updated environment

Using Environment Variables in Telegram Node

Once your variable is defined, here’s how to use it inside the Telegram node:
1. Enable Expression Mode

  • In the Telegram node, locate the Chat ID field
  • Click the gear icon next to the field
  • Choose “Add Expression”
  • Enter:
    {{ $env.TELEGRAM_CHAT_ID }}

Do not paste this directly into a plain text field—it won’t resolve unless entered as an expression.

2. Run the Node
Environment variables only resolve during runtime, not in edit mode.

Confirm that the Telegram message sends correctly

Save your workflow

Final Tips

  • You can verify that your environment variable is loaded by running:
    docker exec -it n8n printenv | grep TELEGRAM_CHAT_ID
  • If the variable appears but still doesn’t resolve, check:
  • That you’re using expression mode
  • That the workflow is executed (not just previewed)
  • That your n8n version supports $env expressions (v1.0+ recommended)

By following these steps, you’ll keep your workflows clean, secure, and scalable—especially when working with sensitive integrations like API Keys and other critical identifiers.

Categories: AI Automation