Can't get n8n to run via pm2 inside package.json

Describe the issue/error/question

I am trying to keep n8n deployed via yarn & pm2. My start script works, but I can’t figure out how to get it working with pm2 in the mix.

What is the error message (if any)?

after running a yarn start:pm2 command I get the following from pm2 logs:

0|n8n      | /usr/share/yarn/bin/yarn:2
0|n8n      | argv0=$(echo "$0" | sed -e 's,\\,/,g')
0|n8n      |         ^^^^
0|n8n      |
0|n8n      | SyntaxError: missing ) after argument list
0|n8n      |     at internalCompileFunction (node:internal/vm:73:18)
0|n8n      |     at wrapSafe (node:internal/modules/cjs/loader:1149:20)
0|n8n      |     at Module._compile (node:internal/modules/cjs/loader:1190:27)
0|n8n      |     at Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
0|n8n      |     at Module.load (node:internal/modules/cjs/loader:1089:32)
0|n8n      |     at Module._load (node:internal/modules/cjs/loader:930:12)
0|n8n      |     at Object.<anonymous> (/home/siteservice-n8n/.nvm/versions/node/v18.14.0/lib/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
0|n8n      |     at Module._compile (node:internal/modules/cjs/loader:1226:14)
0|n8n      |     at Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
0|n8n      |     at Module.load (node:internal/modules/cjs/loader:1089:32)

Please share the workflow

package.json

{
  "name": "n8n",
  "version": "0.0.1",
  "scripts": {
    "start": "N8N_CONFIG_FILES=./config.json WEBHOOK_URL=https://n8n.domain.net/ NODE_FUNCTION_ALLOW_BUILTIN=* NODE_FUNCTION_ALLOW_EXTERNAL=request-promise-native,form-data,axios,node-fetch n8n start",
    "pm2": "N8N_CONFIG_FILES=./config.json WEBHOOK_URL=https://n8n.domain.net/ NODE_FUNCTION_ALLOW_BUILTIN=* NODE_FUNCTION_ALLOW_EXTERNAL=request-promise-native,form-data,axios,node-fetch pm2 start n8n --name n8n",
    "start:pm2": "N8N_CONFIG_FILES=./config.json WEBHOOK_URL=https://n8n.domain.net/ NODE_FUNCTION_ALLOW_BUILTIN=* NODE_FUNCTION_ALLOW_EXTERNAL=request-promise-native,form-data,axios,node-fetch pm2 start n8n --name n8n",
    "save:pm2": "pm2 save"
  },
  "dependencies": {
    "n8n": "^0.217.1"
  }
}

config.json

{
  "database": {
    "type": "mariadb",
    "mysqldb": {
      "database": "n8n",
      "user": "n8n",
      "password": "XXXXXXXXXXXX"
    }
  },
  "userManagement": {
    "emails": {
      "mode": "smtp",
      "smtp": {
        "host": "smtp.gmail.com",
        "port": 465,
        "secure": true,
        "auth": {
          "user": "XXXXXXXXXXX",
          "pass": "XXXXXXXXX"
        },
        "sender": "[n8n]"
      }
    }
  }
}

running yarn start works fine.

Hey @smitty,

Welcome to the community :raised_hands:

It looks like Yarn is outputting an error about the syntax and a missing ) so I guess somewhere you have a ( or something escaping the rest of the line and it is causing an issue.

I have not really used Yarn but maybe someone else has an answer for you, This doesn’t look to be an n8n issue at the moment though.

Thanks, I was able to resolve it by adjusting my start:pm2 line in package.json:

{
  "name": "n8n",
  "version": "0.0.1",
  "scripts": {
    "start": "N8N_CONFIG_FILES=./config.json WEBHOOK_URL=https://n8n.domain.net/ NODE_FUNCTION_ALLOW_BUILTIN=* NODE_FUNCTION_ALLOW_EXTERNAL=request-promise-native,form-data,axios,node-fetch n8n start",
    "start:pm2": "pm2 start npm --name n8n -- start"
  },
  "dependencies": {
    "n8n": "^0.217.1"
  }
}
2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.