0

I have a Postgres database that is hosted on pgAdmin, and I have an API with POST and GET routes. Also, I have test files that set up and populate the database. All that seems to be working fine. When I run my tests, it builds the database with the items in my tests. This is all done on localhost.

However, when I try to make requests with Postman, I receive this error in the terminal:

Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string

[nodemon] starting `node server.js`
Started on port 3001
/Users/francoortega/Documents/Professional/Projects/Practice/Server/demo-server-02-api-database/node_modules/pg/lib/sasl.js:24
    throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string')
    ^

Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string
    at Object.continueSession (/Users/francoortega/Documents/Professional/Projects/Practice/Server/demo-server-02-api-database/node_modules/pg/lib/sasl.js:24:11)
    at Client._handleAuthSASLContinue (/Users/francoortega/Documents/Professional/Projects/Practice/Server/demo-server-02-api-database/node_modules/pg/lib/client.js:257:10)
    at Connection.emit (node:events:394:28)
    at /Users/francoortega/Documents/Professional/Projects/Practice/Server/demo-server-02-api-database/node_modules/pg/lib/connection.js:114:12
    at Parser.parse (/Users/francoortega/Documents/Professional/Projects/Practice/Server/demo-server-02-api-database/node_modules/pg-protocol/dist/parser.js:40:17)
    at Socket.<anonymous> (/Users/francoortega/Documents/Professional/Projects/Practice/Server/demo-server-02-api-database/node_modules/pg-protocol/dist/index.js:11:42)
    at Socket.emit (node:events:394:28)
    at addChunk (node:internal/streams/readable:312:12)
    at readableAddChunk (node:internal/streams/readable:287:9)
    at Socket.Readable.push (node:internal/streams/readable:226:10)
[nodemon] app crashed - waiting for file changes before starting...

I'm guessing that Postman is the client in this case, so do I need to include my Postgres username and password with the request sent via Postman? I tried including them in the Authorization field under Basic Auth, but that didn't make any difference.

EDIT/UDPATE: I built a client (website) on localhost to connect to my database on localhost, and it was having the same issue as Postman. Long story short, I had to launch my database live (I used Heroku/Postgres/pgAdmin), and then both Postman and my localhost client were able to connect to the live database. But they still can't connect to the database when it is set to localhost.

What I'm wondering at this point is: Is there a way to connect a localhost or live client (website, Postman, etc) to a localhost database? It seems like there should be a way to test them together on my local machine, instead of having to launch the database live.

Franco Ortega
  • 29
  • 1
  • 6

1 Answers1

0

I just received help from a friend for a fix. At least a temporary fix. I added this line to the top of my pool.js file:

import dotenv from 'dotenv/config';

The problem seemed to be that the environment variables (process.env.SECRET_STUFF) weren't being accessed from the pool.js file. Now I can connect to my local database from my local frontend and Postman.

Although, my friend also said a better solution would be to add the 'dotenv/config' to a script in the package.json file, but he wasn't sure about the proper syntax was for that, so I'm going to try to find that out next.

Franco Ortega
  • 29
  • 1
  • 6