> ## Documentation Index
> Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 在本機使用 CometAPI 執行 n8n

> 使用本指南，透過設定本機部署、憑證與模型存取，搭配 CometAPI 在本機執行 n8n。

在你自己的電腦上部署 n8n，並透過社群節點將其連接到 CometAPI，以在本機執行自動化 AI 工作流程。

## 先決條件

* Linux（Ubuntu/Debian/CentOS 等）或 macOS
* 2 GB 以上 RAM、10 GB 以上可用磁碟空間
* 可連線至公開 npm registry 的 Shell 存取權限
* Node.js 18.x 或 20.x LTS（請參閱步驟 1）
* 擁有啟用中 API key 的 CometAPI 帳號 — [在此取得](https://www.cometapi.com/console/token)

<Steps>
  <Step title="取得你的 CometAPI API key">
    登入 [CometAPI 主控台](https://www.cometapi.com/console/token)。點擊 **Add API Key**，然後複製你的 CometAPI API key。

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/overview/810968_364191.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=aef81a83f29f8eb16655ed4060425f50" alt="顯示 Add API Key 按鈕的 CometAPI 儀表板" width="3824" height="1892" data-path="images/overview/810968_364191.png" />
    </Frame>

    <Frame>
      <img src="https://mintcdn.com/cometapi/HhtmQffktazbxUvS/images/overview/810968_364193.png?fit=max&auto=format&n=HhtmQffktazbxUvS&q=85&s=d893f659267150d0faf45f99eb5dffc1" alt="包含 base URL 的 CometAPI API key 詳細資訊" width="2434" height="1232" data-path="images/overview/810968_364193.png" />
    </Frame>
  </Step>

  <Step title="透過 nvm 安裝 Node.js">
    n8n 1.x 需要 Node.js 18.x 或 20.x。建議使用 [nvm](https://github.com/nvm-sh/nvm)：

    ```bash theme={null}
    # Install nvm
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

    # Reload your shell profile
    source ~/.bashrc   # or ~/.zshrc on macOS

    # Install and activate the LTS version
    nvm install --lts
    nvm use --lts

    # Verify
    node -v
    npm -v
    ```

    <Note>
      如果你之後看到 `n8n: command not found`，請重新啟動終端機，或確認由 nvm 管理的 npm 全域 bin 目錄已加入你的 `PATH`。
    </Note>
  </Step>

  <Step title="安裝並啟動 n8n">
    ```bash theme={null}
    npm install -g n8n
    n8n -v       # verify the installed version
    n8n start    # runs on http://localhost:5678/
    ```

    如果連接埠 5678 已被使用：

    ```bash theme={null}
    export N8N_PORT=5679
    n8n start
    ```

    若要在關閉終端機後仍持續執行 n8n：

    ```bash theme={null}
    npm install -g pm2
    pm2 start "n8n" --name n8n
    pm2 save
    pm2 status
    ```

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360463.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=80fe6068a8af4ec3b3503ff41d378a17" alt="顯示 n8n 成功啟動的終端機畫面" width="715" height="451" data-path="images/integrations/810968_360463.png" />
    </Frame>

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360464.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=77cadfd218dbe0fef19fe701550ea363" alt="終端機中的 n8n 啟動日誌" width="759" height="460" data-path="images/integrations/810968_360464.png" />
    </Frame>
  </Step>

  <Step title="建立你的 owner 帳號">
    在瀏覽器中開啟 [http://localhost:5678/](http://localhost:5678/)。首次執行時，設定精靈會要求你建立 **Owner** 帳號（電子郵件 + 密碼）。完成後登入。

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360465.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=8fdd100138f2bf01bbf834d9db1ea29e" alt="要求輸入 Owner 帳號詳細資訊的 n8n 首次執行設定精靈" width="1249" height="970" data-path="images/integrations/810968_360465.png" />
    </Frame>
  </Step>

  <Step title="安裝 CometAPI 社群節點">
    1. 前往 **Settings**（左下角）→ **Community nodes**
    2. 點擊 **Install a community node**
    3. 輸入套件名稱：`@cometapi-dev/n8n-nodes-cometapi`
    4. 勾選風險確認方塊，然後點擊 **Install**

    安裝完成後，你可以在節點面板中搜尋 **CometAPI**。

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360467.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=1c107922e16332157d278bf834b3e32a" alt="顯示 Community nodes 區段的 n8n Settings 面板" width="1265" height="975" data-path="images/integrations/810968_360467.png" />
    </Frame>

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360468.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=98c05d77cb6adf333052b4d5014fc506" alt="已輸入 CometAPI 套件名稱的安裝對話框" width="1261" height="965" data-path="images/integrations/810968_360468.png" />
    </Frame>

    <Note>
      如果找不到 Community Nodes 區段：請確認你是以 **Owner** 帳號登入，並檢查 **Settings → Security** 以確認已啟用社群節點安裝。
    </Note>
  </Step>

  <Step title="建立工作流程並設定憑證">
    1. 點擊頂部的 **+ New** 以建立工作流程。
    2. 點擊畫布上的 **+**，搜尋 **CometAPI** 以新增節點。

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360469.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=b47e1304ec3165720dd3ef37e1429485" alt="開啟 CometAPI 節點搜尋的 n8n 工作流程畫布" width="1235" height="899" data-path="images/integrations/810968_360469.png" />
    </Frame>

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360472.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=b765a2d8024f4c5d36305916c440d02f" alt="已加入 n8n 畫布的 CometAPI 節點" width="1724" height="854" data-path="images/integrations/810968_360472.png" />
    </Frame>

    3. 新增一個 **Manual Trigger** 節點，並將其連接到 CometAPI 節點。
    4. 在 CometAPI 節點中，於 **Credential to connect with** 下選擇 **Create new**。將你的 CometAPI API key 貼到 **CometAPI Key**，然後點擊 **Save**。Base URL 預設為 `https://api.cometapi.com`，通常不需要變更。

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360474.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=deee1c999cbfb2c432daaa53904d6b38" alt="已輸入 API key 的 CometAPI 憑證對話框" width="1906" height="608" data-path="images/integrations/810968_360474.png" />
    </Frame>

    5. 設定節點：

    * **Model**：輸入你要使用的目前 model ID
    * **Messages**：將 Role 設為 `user`，Content 設為你的測試 prompt（例如 `Hello`）
    * 選填：加入 `system` 訊息、設定 **Max Tokens**、**Temperature** 等

    6. 點擊 **Execute step** 以執行節點。**Output** 面板會顯示 JSON 回應。

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360471.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=6953b97533f02e4f50cb1f0490ff057d" alt="顯示成功 CometAPI JSON 回應的 n8n 輸出面板" width="2092" height="1762" data-path="images/integrations/810968_360471.png" />
    </Frame>
  </Step>
</Steps>

<AccordionGroup>
  <Accordion title="疑難排解">
    * **`node-gyp` 或原生建置錯誤** — 安裝建置工具：`sudo apt install build-essential python3`（Debian/Ubuntu）或 Xcode Command Line Tools（macOS）。
    * **npm 權限錯誤（EACCES）** — 使用 nvm 進行使用者層級的 Node.js 安裝；不需要 `sudo`。
    * **連接埠衝突（`localhost:5678` 無法使用）** — 在執行 `n8n start` 前設定 `N8N_PORT=5679`（或其他可用連接埠）。
    * **缺少 Community Nodes 區段** — 以 **Owner** 帳號登入並檢查 **Settings → Security**。
    * **公司網路環境下 npm install 失敗** — 設定 proxy：`npm config set proxy http://user:pass@host:port`
    * **CometAPI 節點回傳 401/403** — 驗證你的 API key，並確認你的 CometAPI 方案可存取該模型。
    * **空白回應或 Token 限制錯誤** — 增加 **Max Tokens**；視需要調整 **Temperature** 與 **Top P**。
    * **關閉終端機後 n8n 停止執行** — 使用 pm2：`pm2 start "n8n" --name n8n && pm2 save`。
  </Accordion>
</AccordionGroup>

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "HowTo",
        "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#howto",
        "name": "在本機搭配 CometAPI 執行 n8n",
        "description": "使用本指南，透過設定本機部署設定、憑證與模型存取，在本機搭配 CometAPI 執行 n8n。",
        "step": [
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-1",
            "position": 1,
            "name": "取得你的 CometAPI API key",
            "text": "建立或開啟你的 CometAPI 帳號，然後從儀表板複製一組啟用中的 API key。"
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-2",
            "position": 2,
            "name": "透過 nvm 安裝 Node.js",
            "text": "完成〈在本機搭配 CometAPI 執行 n8n〉指南中的「透過 nvm 安裝 Node.js」步驟。"
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-3",
            "position": 3,
            "name": "安裝並啟動 n8n",
            "text": "完成〈在本機搭配 CometAPI 執行 n8n〉指南中的「安裝並啟動 n8n」步驟。"
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-4",
            "position": 4,
            "name": "建立你的 owner 帳號",
            "text": "完成〈在本機搭配 CometAPI 執行 n8n〉指南中的「建立你的 owner 帳號」步驟。"
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-5",
            "position": 5,
            "name": "安裝 CometAPI 社群節點",
            "text": "完成〈在本機搭配 CometAPI 執行 n8n〉指南中的「安裝 CometAPI 社群節點」步驟。"
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-6",
            "position": 6,
            "name": "建立工作流程並設定憑證",
            "text": "完成〈在本機搭配 CometAPI 執行 n8n〉指南中的「建立工作流程並設定憑證」步驟。"
          }
        ]
      },
      {
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "CometAPI 文件",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "整合",
            "item": "https://apidoc.cometapi.com/integrations"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "在本機搭配 CometAPI 執行 n8n",
            "item": "https://apidoc.cometapi.com/integrations/n8n-local-deployment"
          }
        ]
      }
    ]
    }
    `}
</script>
