7

I've been following the official docs for deploying a Strapi app onto Digital ocean, but I'm having trouble setting up pm2. It starts the app for a second, and then shows

status: errored

there's no script.js to run the app, but when I cd to /home/myusername/appname/backend and run npm start, it works just fine, which leads me to believe that I have the ENV variables set correctly

Here's the config file

module.exports = {
  apps: [
    {
      name: 'strapi',
      cwd: '/home/your-name/project/backend',
      script: 'npm',
      args: 'start',
      env: {
        NODE_ENV: 'production',
        DATABASE_HOST: 'localhost', // database endpoint
        DATABASE_PORT: '5432',
        DATABASE_NAME: 'strapi', // DB name
        DATABASE_USERNAME: 'your-name', // your username for psql
        DATABASE_PASSWORD: 'password', // your password for psql
      },
    },
  ],
};

Then I run pm2 logs, I see

2020-07-13T01:58:49: PM2 log: App [strapi:0] online
PM2        | 2020-07-13T01:58:49: PM2 error: Error: spawn node ENOENT
PM2        |     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
PM2        |     at onErrorNT (internal/child_process.js:415:16)
PM2        |     at process._tickCallback (internal/process/next_tick.js:63:19)

Thanks

web master
  • 255
  • 2
  • 8

2 Answers2

9
  1. First replace:
    NODE_ENV: 'production',
    DATABASE_HOST: '127.0.0.1', // database endpoint
    DATABASE_PORT: '5432',
    DATABASE_NAME: 'THE DB NAME EX.SAMMY'
    DATABASE_USERNAME: 'THE DB USERNAME EX.SAMMY'
    DATABASE_PASSWORD: 'THE DB PASSWORD'
  1. pm2 del 0 (check strapi app with pm2 start)

  2. pm2 start ecosystem.config.js

Alwaysblue
  • 9,948
  • 38
  • 121
  • 210
8

for me it was because cwd was already relative and didn't like how my path was structured. I tried ~/my-app as well as /home/me/my-app and both were wrong. It eventually just wanted my-app.

okwme
  • 740
  • 1
  • 7
  • 19
  • 1
    That was my exact problem. Not the formatting, but just I had an invalid path for my `cwd`. It was a simple mistake but once I corrected it - I was online with no error. Thanks! – SeanMC Dec 31 '20 at 15:14
  • 1
    Same problem deploying to EC2. Solved with this, thanks! – Andres9619 Jun 10 '21 at 01:51