node.jsherokucommand-line-interfaceprocfileappjs

Cannot deploy Node.js app with Heroku: "bash: app.js: command not found"


I have built a server side app using Node.js. When trying to deploy the app to Heroku, I'm receiving an "Application error" message on Heroku page via my Heroku project's dashboard. When looking at the logs, I'm seeing the following error:

2021-11-30T10:11:16.238229+00:00 heroku[web.1]: Starting process with command `app.js`
2021-11-30T10:11:16.969594+00:00 app[web.1]: **bash: app.js: command not found**
2021-11-30T10:11:17.091877+00:00 heroku[web.1]: Process exited with status 127
2021-11-30T10:11:17.159203+00:00 heroku[web.1]: State changed from starting to crashed

I've verified that I have npm and node installed correctly, All similar errors I found online are related to uninstalled node, but the errors were "node: command not found", and the error I am getting is different.

My Procfile content:

web: app.js

The Procfile's name is with capital letters and no extension. The app.js file is where I want the app to start from. I have changed my original app.js file to the following, to make sure it has noting to do with its content:

console.log('hey!')

And inside package.json:

    "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1", 
    "start": "node app.js" 
  },

I'm not sure if it has anything to do with launch.json file, but it contains the following:

        {
    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-chrome",
            "request": "launch",
            "name": "Launch Chrome against localhost",
            "url": "http://localhost:8080",
            "webRoot": "${workspaceFolder}"
        }
    ]
}

You can see localhost and an arbitrary port number under "url". It may be one reason why my app won't work in general, but I'm not sure that is the reason for the error I am getting at the moment (the one I mentioned above in bold font).


Solution

  • My Procfile content:

    web: app.js
    

    That's your problem.

    If a Procfile exists, Heroku will run the command given there over the command given in your start script. You need to run node and pass your script name in:

    web: node app.js