0

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
  • Welcome to Stack Overflow. Please take the [tour] and read [ask]. [Please don't post screenshots of text](https://meta.stackoverflow.com/a/285557/354577). They can't be searched or copied, or even consumed by users of adaptive technologies like screen readers. Instead, paste the code as text directly into your question. If you select it and click the `{}` button or Ctrl+K the code block will be indented by four spaces, which will cause it to be rendered as code. And if you _do_ share screenshots, please only use the official image host by pasting into the edit box. – ChrisGPT was on strike Mar 15 '22 at 15:37

2 Answers2

0

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"
},
Nima
  • 996
  • 2
  • 9
  • 37
  • i attempted what you suggested but the issue still persist. though reference to nodemon in the error is no longer there below is the error I see https://www.dropbox.com/s/77d1x1cij2nsy77/error%201.PNG?dl=0 https://www.dropbox.com/s/j564ot3mq2v44ya/error2.PNG?dl=0 – Ifeanyi Bardi Mar 17 '22 at 15:52
0

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

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • the path environment is well set but still having same error connecting to the database on heroku got the following errors https://www.dropbox.com/s/77d1x1cij2nsy77/error%201.PNG?dl=0 https://www.dropbox.com/s/j564ot3mq2v44ya/error2.PNG?dl=0 – Ifeanyi Bardi Mar 17 '22 at 15:41
  • i also have database locally setup – Ifeanyi Bardi Mar 17 '22 at 15:50
  • @IfeanyiBardi, again, _[please don't post screenshots of text](https://meta.stackoverflow.com/a/285557/354577)_. And all errors should be edited into your question, not posted as comments. – ChrisGPT was on strike Mar 17 '22 at 19:30
  • And you _still_ have two different, unrelated errors. The solution to the database connection issue remains what I wrote above. Can you run `psql` on the command-line from the project directory? – ChrisGPT was on strike Mar 17 '22 at 19:33