0

I'm trying to do a simple getting-started exercise using dockerized postgres + a nodejs connction on windows. I ran:

$ docker run -d --name dev-postgres -e POSTGRES_PASSWORD=testpw  -p 5432:5432 postgres      
701682e86a66f7efb81af2ebb3a92d442c52742d2cd3d008de690bf1fa73d896

And then am using the following snippet from the pg library:

const { Client } = require("pg");
const connectionString = "postgresql://postgres:testpw@localhost:5432/postgres";

const client = new Client({
  connectionString,
});
client.connect();

client.query("SELECT $1::text as message", ["Hello world!"], (err, res) => {
  console.log(err ? err.stack : res.rows[0].message); // Hello World!
  client.end();
});

But it crashes with:

(node:8764) UnhandledPromiseRejectionWarning: error: password authentication failed for user "postgres"
    at Parser.parseErrorMessage (C:\Users\MikeSolomon\devel\user-flow-processor\vidgen\node_modules\pg-protocol\dist\parser.js:278:15)
    at Parser.handlePacket (C:\Users\MikeSolomon\devel\user-flow-processor\vidgen\node_modules\pg-protocol\dist\parser.js:126:29)
    at Parser.parse (C:\Users\MikeSolomon\devel\user-flow-processor\vidgen\node_modules\pg-protocol\dist\parser.js:39:38)
    at Socket.<anonymous> (C:\Users\MikeSolomon\devel\user-flow-processor\vidgen\node_modules\pg-protocol\dist\index.js:10:42)
    at Socket.emit (events.js:310:20)
    at addChunk (_stream_readable.js:286:12)
    at readableAddChunk (_stream_readable.js:268:9)
    at Socket.Readable.push (_stream_readable.js:209:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
(node:8764) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use 
the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:8764) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Error: Connection terminated unexpectedly
    at Connection.<anonymous> (C:\Users\MikeSolomon\devel\user-flow-processor\vidgen\node_modules\pg\lib\client.js:132:73)
    at Object.onceWrapper (events.js:416:28)
    at Connection.emit (events.js:310:20)
    at Socket.<anonymous> (C:\Users\MikeSolomon\devel\user-flow-processor\vidgen\node_modules\pg\lib\connection.js:58:12)
    at Socket.emit (events.js:310:20)
    at TCP.<anonymous> (net.js:672:12)

I've tried several different to get the config working, but none has panned out yet. Can anybody spot what I'm doing wrong? Is this a Windows issue? I checked the docker container using exec bash and can use psql without any issues from within the container. Thanks for your help!

1 Answer 1

1

Word to the wise - it turns out that, on Windows, if you have another instance of postgres running on 5432, this will fail in this way. The solution for me was to simply stop that instance. Unfortunately, as it was a background process that started on system start, it took me a while to figure out it was there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.