Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pm2 error while deploying Strapi App on DigitalOcean

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

like image 404
web master Avatar asked Jul 13 '20 02:07

web master


People also ask

Where do I deploy Strapi app?

Strapi can be deployed on traditional hosting servers or services such as 21YunBox, Render, Heroku, AWS, Azure and others.

How do you deploy a Strapi project?

Install Strapi Locally. Push your Strapi codebase to Github. Connect your Heroku account to your Github(the project repository) and enable Automatic Deploy. Connect your Strapi project to Postgres add-on database provided by Heroku.


Video Answer


2 Answers

  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

like image 101
michael.marid Avatar answered Oct 19 '22 19:10

michael.marid


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.

like image 22
okwme Avatar answered Oct 19 '22 19:10

okwme