Can't auto start n8n with pm2 on windows

Describe the problem/error/question

I’m trying to make n8n auto start on boot so I’m using pm2 but it’s unable to launch n8n in pm2. I can launch n8n locally but not within pm2

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • **n8n version: 1.81.4
  • **Database (default: SQLite): default
  • **n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • **Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • **Operating system: Windows Server 2022

Hey @Ruriko,

I would recommend using Docker instead of pm2, If you do want to continue using pm2 it may be worth checking the pm2 log output to see why it is not running.

I don’t want use docker cause it uses more system resources. I had a look at pm2 log and this is what it says:

C:\USERS\ADMINISTRATOR\APPDATA\ROAMING\NPM\N8N.CMD:1
@ECHO off
^

SyntaxError: Invalid or unexpected token
    at wrapSafe (node:internal/modules/cjs/loader:1486:18)
    at Module._compile (node:internal/modules/cjs/loader:1528:20)
    at Object..js (node:internal/modules/cjs/loader:1706:10)
    at Module.load (node:internal/modules/cjs/loader:1289:32)
    at Function._load (node:internal/modules/cjs/loader:1108:12)
    at Object.<anonymous> (C:\ProgramData\pm2-etc\node_modules\pm2\lib\ProcessContainerFork.js:33:23)
    at Module._compile (node:internal/modules/cjs/loader:1554:14)
    at Object..js (node:internal/modules/cjs/loader:1706:10)
    at Module.load (node:internal/modules/cjs/loader:1289:32)
    at Function._load (node:internal/modules/cjs/loader:1108:12)

I think it interprets n8n.cmd as a Javascript code

It looks that way, Sadly as we don’t officially support pm2 though I am not sure what the best fix would be there.

Have you made an ecosystem file yet I have seen users take that approach in the past and it has worked.

When it comes to docker and resources in theory it is very light weight and less hassle as our containers have everything you need and are less prone to issues caused by system changes this is why we recommend containers in production environments.

I never used ecosystem file before. How do I setup?

Give this a bash: PM2 - Ecosystem File

We do have an old blog post that might help as well: How to set up n8n via PM2 – n8n Blog