Search code examples
node.jsherokusocket.iopermissionsnodemon

Heroku Throwing Error When Running Server


I recently made a server that works locally. However, when try to host it on Heroku, I am getting quiet a lot of errors (most of which I have fixed, but one I cannot seem to solve). One error was that the code I wrote didn't listen on the right port (now changed to process.env.PORT || 3000, which works), and another error about nodemon not being present. I fixed it in the dependency part of my package.json file by adding "nodemon": "^2.0.4", which clears that up nicely.

However, I may have fixed those, but now when I push my commits and stuff to Heroku and load up my server, the webpage says: Application error.

I go to look in the logs (heroku logs --tail) and I have a new error.

2020-08-14T23:43:55.764028+00:00 app[web.1]: [nodemon] starting `src/app.js`
2020-08-14T23:43:55.783805+00:00 app[web.1]: sh: 1: src/app.js: Permission denied
2020-08-14T23:43:55.799270+00:00 app[web.1]: [nodemon] app crashed - waiting for file changes before starting...

What is causing the inability to access src/app.js? A couple of sites have said to run:

npm config set user 0
npm config set unsafe-perm true

But I'm unsure how to do this with Heroku. Also, some have said it's unsafe, so not sure if I want to do this.

Is there a very simple way to fix this? Most of my errors aren't that hard, but this one has been an absolute plaque to me.

Thanks in advance!!


Solution

  • I actually fixed this issue by taking all of my files out of src (and then add node app.js as the start command) which seems to clear up the Heroku issue quiet nicely.