Question

My express app wont start

Hello. I’m attempting to run a simple express app with the command sudo -u nodejs pm2 start --name aboutme app.js\ but keep getting error. I look in logs and see PM2 error: Error: spawn /usr/bin/bash EACCES Any advice? link to app here. link to screenshot here.


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.

Bobby Iliev
Site Moderator
Site Moderator badge
October 3, 2022
Accepted Answer

Hi there,

It sounds like that your nodejs user does not have access to the /root directory.

I’ve just tested running the project with the root user directly and it works well:

pm2 start app.js
[PM2] Applying action restartProcessId on app [app](ids: 0)
[PM2] [app](0) ✓
[PM2] Process successfully started

What you could do is:

  • Run pm2 as the root user
  • Alternatively, switch to the nodejs user, and git clone the project into the nodejs user’s home directory, that way the nmodejs user will be the owner of the files and would not have that permissions problem

Let me know how it goes!

Best,

Bobby

KFSys
Site Moderator
Site Moderator badge
October 3, 2022

Hi @henriavo,

This sounds like a permissions/ownership issue. See if your have set some weird permissions most of all. Usually, and I believe the express app has the same permissions, they need to be 755 for folders nad 644 for files. You can do that for a faster outcome:

  1. find /path/to/express/app -f -exec chmod 644 {} \;
  2. find /path/to/express/app -d -exec chmod 755 {} \;

Where /path/to/express/app should be the real path.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel