Home > Blockchain >  Cannot connect to my databse addon on heroku
Cannot connect to my databse addon on heroku

Time:03-16

I attempted to use the command Heroku pg:psql to connect to my database addon in heroku but got a response below

--> Connecting to postgresql-regular-61345
unrecognized win32 error code: 123could not find a "psql" to execute
unrecognized win32 error code: 123could not find a "psql" to execute
psql: fatal: could not find own program executable
 !    psql exited with code 1

After using the heroku logs --tail command i got the following errors

sh: 1: nodemon: not found
Process exited with status 127
State changed from starting to crashed

I can also see all processes stopping with SIGTERM and the process exiting with status 143

Resolution steps I have taken

  1. Verified that the environment variables have the path for installed postgress14 on my PC

  2. Added a procfile to the root file in my backend code and spcified "web: node matthewfaceappback/server.js in the file"

  3. Changed my set port to a variable port using process.env.PORT || 3000

  4. Set all environment variable including my database url(set by default) on config variable in heroku

  5. Verified there is a start up script

  6. Updated all my packages using "npm update". after doing this i started expereincing the issue of processes stopping with SIGTERM and the process exiting with status 143

  7. I moved nodemon from devDependencies to dependencies. nodemon version is 2.0.15

  8. In package.json i inputed an engines parameter using the version of node in my case

    {"engines": { "node": "14.17.4" }}

  9. I restarted heroku using "heroku restart"

Below are links to the screenshots of the error

https://www.dropbox.com/s/5bdbyi9e99lbxhu/pic1.PNG?dl=0
https://www.dropbox.com/s/41euniaes5q68c9/pic2.PNG?dl=0
https://www.dropbox.com/s/50oqzbwmwrqogax/pic3.PNG?dl=0

CodePudding user response:

Put nodemon back in the devDependencies and add it as a second node script in package.json:

"scripts": {
  "start": "node matthewfaceappback/server.js",
  "dev": "nodemon matthewfaceappback/server.js"
},

CodePudding user response:

These two errors are completely unrelated.

The database connection error

The first issue, which I believe is the one you actually care about at the moment based on the title of the question, indicates that the Heroku CLI can't find a PostgreSQL client on your local machine.

The documentation makes the following recommendation

Set up Postgres on Windows

Install Postgres on Windows by using the Windows installer.

Remember to update your PATH environment variable to add the bin directory of your Postgres installation. The directory is similar to: C:\Program Files\PostgreSQL\<VERSION>\bin. Commands like heroku pg:psql depend on the PATH and do not work if the PATH is incorrect.

If you haven't already installed Postgres locally, do so. (This is a good idea anyway as you should be developing locally and you'll probably need a database.)

Then make sure to add its bin/ directory to your PATH environment variable.

The Nodemon error

The second issue is because you are trying to use nodemon in production. Heroku strips development dependencies out of Node.js applications after building them, which normally makes sense. Nodemon is a development tool, not something that should be used for production hosting.

Depending on the contents of your package.json, this might be as simple as changing your start script from nodemon some-script.js to node some-script.js. Alternatively, you can add a Procfile with the command you actually want to run on Heroku:

web: node some-script.js

See also Need help deploying a RESTful API created with MongoDB Atlas and Express

  • Related