PM2 - cannot start my node app using custom cwd in ecosystem.json
Asked Answered
C

1

9

My node app is deployed in /opt/hello/current but when I start PM2 (pm2 startOrReload ecosystem.json --env production) with the following ecosystem.json , it doesn't seems to take in account the given parameters...

  "apps" : [
    {
      "name": "hello",
      "cwd": "/opt/hello/current",  // the directory from which your app will be launched
      "script": "./hello.js", // script path relative to pm2 start
      "args": "",
      "watch": false,
      "node_args": "",
      "merge_logs": true,
      "env" : {
        "NODE_ENV": "development"
      },
      "env_staging" : {
        "NODE_ENV": "staging"
      },
      "env_production" : {
        "NODE_ENV": "production"
      }
    }]

It should start the script (./hello.js) relatively from "cwd" (/opt/hello/current) ... am I wrong ?

It's currently starting with path /opt/hello/hello.js

Catwalk answered 29/11, 2016 at 13:24 Comment(0)
C
18

you need to specify a directory path for cwd, in this case, just add a / at the end like so :

 "apps" : [
    {
      "name": "hello",
      "cwd": "/opt/hello/current/",  // / added here
      "script": "./hello.js",
      "args": "",
      "watch": false,
      "node_args": "",
      "merge_logs": true,
      "env" : {
        "NODE_ENV": "development"
      },
      "env_staging" : {
        "NODE_ENV": "staging"
      },
      "env_production" : {
        "NODE_ENV": "production"
      }
    }]
Cynar answered 29/11, 2016 at 13:36 Comment(2)
Thanks a lot ... it's now running fine... I noticed that I had to delete the previous running 'hello' app w wrong path , to get the new one running fine ...Catwalk
If it has solved your issue, maybe you should consider accepting it as an answer.Finagle

© 2022 - 2024 — McMap. All rights reserved.