postgres - password authentication fails from windows docker container - javascript

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!

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.

Related

Unable to get local issuer certificate in node js

I am new to the node js.I am getting this error while running my node js code in local. Please help me in this.
(node:7532) UnhandledPromiseRejectionWarning: Error: unable to get local issuer certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1048:34)
at TLSSocket.emit (events.js:182:13)
at TLSSocket._finishInit (_tls_wrap.js:628:8)
(node:7532) 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(). (rejection id: 1)
(node:7532) [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.
I tried some of the available solution on the internet, but so far any of them are working.
This are the things I have tried.
npm set strict-ssl=false
npm config set strict-ssl false
export NODE_TLS_REJECT_UNAUTHORIZED=0

I get "TypeError: Cannot read property 'tag' of null" but only in the packaged version of my discord.js bot

I am working on a discord bot in discord.js and everything has been working just fine. But I want to compile it into a .exe file for ease of use, etc. I can run the bot fine just using node.js but when I run the .exe I get the following error message:
(node:3656) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'tag' of null
at Client.<anonymous> (C:\snapshot\src\index.js:19:42)
at Client.emit (events.js:315:20)
at WebSocketManager.triggerClientReady (C:\snapshot\src\node_modules\discord.js\src\client\websocket\WebSocketManager.js:431:17)
at WebSocketManager.checkShardsReady (C:\snapshot\src\node_modules\discord.js\src\client\websocket\WebSocketManager.js:415:10)
at WebSocketShard.<anonymous> (C:\snapshot\src\node_modules\discord.js\src\client\websocket\WebSocketManager.js:197:14)
at WebSocketShard.emit (events.js:315:20)
at WebSocketShard.checkReady (C:\snapshot\src\node_modules\discord.js\src\client\websocket\WebSocketShard.js:475:12)
at WebSocketShard.onPacket (C:\snapshot\src\node_modules\discord.js\src\client\websocket\WebSocketShard.js:447:16)
at WebSocketShard.onMessage (C:\snapshot\src\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\snapshot\src\node_modules\ws\lib\event-target.js:132:16)
(Use `jamesinasbot --trace-warnings ...` to show where the warning was created)
(node:3656) 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:3656) [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.
This is the line with the issue:
console.log(`Logged in as ${client.user.tag}.`);
I am not sure why this happens. I have made sure all the dependencies are included, it is in the same directory as index.js, and since it is only saying it can't read the property tag of null it seems to be an issue with variables or something not dependencies. I have tried using --trace-warnings but it doesn't show anything different.
Any help is appreciated!

AWS Amplify error: (node:68674) UnhandledPromiseRejectionWarning: NoSuchKey: The specified key does not exist

I am applying Amplify in Vue.js,
so the issue here is after I've done command successfully :
amplify add api
then I am trying to do command:
amplify push
Then below error always there:
SKY-MacBook-Pro:my-project sky$ amplify push ⠇ Fetching updates to
backend environment: mpvue from the cloud.(node:68674)
UnhandledPromiseRejectionWarning: NoSuchKey: The specified key does
not exist.
at Request.extractError (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/services/s3.js:816:35)
at Request.callListeners (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request. (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/request.js:38:9)
at Request. (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
(node:68674) 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(). (rejection id: 1) (node:68674) [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. ⠹ Fetching updates to
backend environment: mpvue from the cloud. SKY-MacBook-Pro:my-project
sky$
Here is the docs for your reference:
https://aws-amplify.github.io/docs/js/start?platform=vue

Puppeteer Script Works Local But Not On EC2 AWS

I am running the following script on EC2 AWS with Amazon Linux AMI
const puppeteer = require('puppeteer');
url_ = 'https://www.barchart.com/futures/quotes/ES*0/interactive-chart/fullscreen';
func()
async function func() {
console.log(0)
const browser = await puppeteer.launch();
console.log(1)
const page = await browser.newPage();
console.log(2)
await page.goto(url_);
console.log(page)
return page
}
since today, with no changes on or new installs on EC2, the script stopped working while it was working until yesterday.
The same script on Local Machine still works.
Instead on EC2 gives the following error:
(node:12636) UnhandledPromiseRejectionWarning: Error: Navigation failed because browser has disconnected!
at CDPSession.LifecycleWatcher._eventListeners.helper.addEventListener (/home/ec2-user/hd/node_modules/puppeteer/lib/LifecycleWatcher.js:47:107)
at CDPSession.emit (events.js:189:13)
at CDPSession._onClosed (/home/ec2-user/hd/node_modules/puppeteer/lib/Connection.js:215:10)
at Connection._onClose (/home/ec2-user/hd/node_modules/puppeteer/lib/Connection.js:138:15)
at WebSocketTransport._ws.addEventListener.event (/home/ec2-user/hd/node_modules/puppeteer/lib/WebSocketTransport.js:45:22)
at WebSocket.onClose (/home/ec2-user/hd/node_modules/ws/lib/event-target.js:124:16)
at WebSocket.emit (events.js:189:13)
at WebSocket.emitClose (/home/ec2-user/hd/node_modules/ws/lib/websocket.js:191:10)
at Socket.socketOnClose (/home/ec2-user/hd/node_modules/ws/lib/websocket.js:850:15)
at Socket.emit (events.js:189:13)
-- ASYNC --
at Frame. (/home/ec2-user/hd/node_modules/puppeteer/lib/helper.js:110:27)
at Page.goto (/home/ec2-user/hd/node_modules/puppeteer/lib/Page.js:656:49)
at Page. (/home/ec2-user/hd/node_modules/puppeteer/lib/helper.js:111:23)
at func (/home/ec2-user/hd/scrape_bk.js:19:13)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:12636) 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(). (rejection id: 1)
(node:12636) [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.
if I give instead this URL (http://www.google.com) I get this error on EC2 (while it still works on local machine):
(node:12938) UnhandledPromiseRejectionWarning: Error: Page crashed!
at Page._onTargetCrashed (/home/ec2-user/hd/node_modules/puppeteer/lib/Page.js:185:24)
at CDPSession.Page.client.on.event (/home/ec2-user/hd/node_modules/puppeteer/lib/Page.js:140:56)
at CDPSession.emit (events.js:189:13)
at CDPSession._onMessage (/home/ec2-user/hd/node_modules/puppeteer/lib/Connection.js:200:12)
at Connection._onMessage (/home/ec2-user/hd/node_modules/puppeteer/lib/Connection.js:112:17)
at WebSocketTransport._ws.addEventListener.event (/home/ec2-user/hd/node_modules/puppeteer/lib/WebSocketTransport.js:41:24)
at WebSocket.onMessage (/home/ec2-user/hd/node_modules/ws/lib/event-target.js:120:16)
at WebSocket.emit (events.js:189:13)
at Receiver.receiverOnMessage (/home/ec2-user/hd/node_modules/ws/lib/websocket.js:789:20)
at Receiver.emit (events.js:189:13)
(node:12938) 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(). (rejection id: 1)
(node:12938) [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.
(node:12938) UnhandledPromiseRejectionWarning: Error: Navigation failed because browser has disconnected!
at CDPSession.LifecycleWatcher._eventListeners.helper.addEventListener (/home/ec2-user/hd/node_modules/puppeteer/lib/LifecycleWatcher.js:47:107)
at CDPSession.emit (events.js:189:13)
at CDPSession._onClosed (/home/ec2-user/hd/node_modules/puppeteer/lib/Connection.js:215:10)
at Connection._onClose (/home/ec2-user/hd/node_modules/puppeteer/lib/Connection.js:138:15)
at WebSocketTransport._ws.addEventListener.event (/home/ec2-user/hd/node_modules/puppeteer/lib/WebSocketTransport.js:45:22)
at WebSocket.onClose (/home/ec2-user/hd/node_modules/ws/lib/event-target.js:124:16)
at WebSocket.emit (events.js:189:13)
at WebSocket.emitClose (/home/ec2-user/hd/node_modules/ws/lib/websocket.js:191:10)
at Socket.socketOnClose (/home/ec2-user/hd/node_modules/ws/lib/websocket.js:850:15)
at Socket.emit (events.js:189:13)
-- ASYNC --
at Frame. (/home/ec2-user/hd/node_modules/puppeteer/lib/helper.js:110:27)
at Page.goto (/home/ec2-user/hd/node_modules/puppeteer/lib/Page.js:656:49)
at Page. (/home/ec2-user/hd/node_modules/puppeteer/lib/helper.js:111:23)
at func (/home/ec2-user/hd/scrape_bk.js:13:13)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:12938) 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(). (rejection id: 2)
I have no idea how to identify the source of the problem since it came out suddenly with no changes to machine or code and on my local machine it works fine.
It seems puppeteer is able to start the browser but it then randomly crashes. This should not be happening on a normal machine and might be happening due to resource constraints.
You should check if your system is running correctly. In particular, you might want to check:
Memory usage
CPU usage
Disk usage
Too few memory or not enough CPU power might lead to random crashes as well as not enough hard disk space.

MikroORM failed to connect to database lireddit on postgresql://postgres#127.0.0.1:5432

I've been trying to solve this bug for 5 hours but it doesn't work. :c Pls help me.
Here is the ugly console error message(im not pro at formatting sry :c):
P:\.Projektek\lireddit-server>yarn dev
yarn run v1.22.10
$ nodemon dist/index.js
[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node dist/index.js`
[discovery] ORM entity discovery started, using ReflectMetadataProvider
[discovery] - processing entity Post
[discovery] - entity discovery finished, found 1 entities, took 22 ms
[info] MikroORM failed to connect to database lireddit on postgresql://postgres#127.0.0.1:5432
(node:8672) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:8672) 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: 8)
(node:8672) [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.
[nodemon] clean exit - waiting for changes before restart
It's so painful.
CREATE USER postgres SUPERUSER;
try creating postgres db
createdb {db_name}
ok, even i have faced this issue. Problem from my end was that database name was spelled incorrectly in my config file.
Here you can do following things.
Make sure you have postgres server running
Make sure you have created the db of lireddit. Type \conninfo in your postgres terminal it will give details such has database,portnumber and so on.
Hope that helps if not lemme know will guide you. Cheers!

Categories