Deploying a React app using pm2 and serve in App Platform

Hi, I am trying to setup PM2 to run a React app I am deploying using the App Platform. The purpose is to have PM2 to automatically restart the app in case it crashes. However I am not able to properly configure the app.yaml to make it work. An example of the app.yaml that I have is:

  - name: app
    build_command: npm install pm2 serve -g && npm run build
    environment_slug: node-js
      branch: main
      deploy_on_push: true
      repo: repo/app
    http_port: 8080
    instance_count: 1
    instance_size_slug: professional-xs
      - path: /
    run_command: pm2-runtime serve build 8080 --spa
    source_dir: /

With these settings, the app deploys, but when I try to access it using the app URL, I get a page that shows the file directory. Also I get two PM2 looping errors after the build:

PM2 error: Error caught while calling pidusage
PM2 error: Error: ESPIPE: invalid seek, read

Probably I am not using a proper run command. Also, should I be using pm2 or pm2-runtime?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

👋 @mateusAxolotl

This is occurring because pidusage uses an underlying SYSCALL which is not available on App Platform, this is part of our underlying sandbox technology called gVisor. Here’s a thread of users who’ve run into this on gVisor based services, like App Platform and Google Cloud Run.

The good news is that for monitoring your app and restarting it on crashes is already a built-in feature of App Platform. Running node app.js should be all you need.

In addition, we recently released alerts and notifications which support getting alerts on restart counts. Here’s a youtube video talking all about this feature.

Hope this helps!