Node app can't authenticate and connect postgres docker container - node.js

So I'm trying to get a node app to connect and authenticate properly to a postgres db running in docker. I'm supposed to run a script that adds data to one of the dbs I add to the container but it's keep throwing this error:
error: password authentication failed for user "myuser"
at Parser.parseErrorMessage (.../node_modules/pg-protocol/dist/parser.js:278:15)
at Parser.handlePacket (.../node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (.../node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.<anonymous> (.../node_modules/pg-protocol/dist/index.js:10:42)
at Socket.emit (events.js:315:20)
at addChunk (internal/streams/readable.js:309:12)
at readableAddChunk (internal/streams/readable.js:284:9)
at Socket.Readable.push (internal/streams/readable.js:223:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # migrate: `knex migrate:latest`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # migrate script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! .../.npm/_logs/2021-03-30T21_21_55_132Z-debug.log
According to the instructions in the github I'm supposed to create a postgres container using this:
docker run --name "postgres" -e POSTGRES_USER='{add-postgres-user}' -e POSTGRES_PASSWORD='{add-postgres-password}' -p 5432:5432 -d -t kartoza/postgis:12.4
I'm able to connect to it using psql and perform queries on it ok with the password and user I entered. However when I enter the same information in an env file the script reads it fails:
POSTGRES_HOST=172.17.0.2
POSTGRES_PORT=5432
POSTGRES_USER=myuser
POSRGRES_PASSWORD=password
POSRGRES_DATABASE=db_example
I've tried changing POSTGRES_HOST to things like localhost, the container name, 127.0.0.1 but no matter what I change it to it fails. I made sure the db was entered like the instructions said. I'm not sure if it has to do with the host binding of the docker image but I thought the 172 address it runs on is the right one. I'm running Ubuntu 20.04 with node 14.16.0.

Thanks to Robert Kawecki, the last two environment variables have typos:
POSRGRES_PASSWORD=password
POSRGRES_DATABASE=db_example

Related

Error when creating Cube.js API - Failure at cubestore

I'm working with Cube.js as part of an effort to create a database with front-end visualization. I'm new to the whole system, and am attempting to follow a tutorial posted here:
https://d3-dashboard.cube.dev/setting-up-a-database-and-cube-js
I have the Postgres database established, but when I go to scaffold the project with:
npx cubejs-cli create d3-dashboard -d postgres
I am receiving an error (below), which seems to be associated with #cubejs-backend\cubestore.
I'm not sure if this is associated with my setup of Node.js. I installed version 14.16.1 and later through some other troubleshooting upgraded npm to version 7.9.0.
Here's the error I'm seeing - any help greatly appreciated:
found 0 vulnerabilities
- Writing files from template
- Installing Cube Store driver
npm ERR! code 1
npm ERR! path C:\Program Files\nodejs\node_modules\d3-dashboard\node_modules\#cubejs-backend\cubestore
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c ./bin/post-install
npm ERR! '.' is not recognized as an internal or external command,
npm ERR! operable program or batch file.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\allenc\AppData\Local\npm-cache\_logs\2021-04-09T16_17_36_455Z-debug.log
Cube.js Error ---------------------------------------
Error: npm install --save-dev #cubejs-backend/cubestore-driver failed with exit code 1
at ChildProcess.<anonymous> (C:\Users\allenc\AppData\Local\npm-cache\_npx\b15e41626979eec6\node_modules\cubejs-cli\src\utils.ts:14:16)
at ChildProcess.emit (events.js:315:20)
at ChildProcess.cp.emit (C:\Users\allenc\AppData\Local\npm-cache\_npx\b15e41626979eec6\node_modules\cross-spawn\lib\enoent.js:34:29)
at maybeClose (internal/child_process.js:1048:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
It's was an issue, which was already fixed. Can you try with latest releases?
Thanks

Mongodb EHOSTUNREACH on Openshift Online 3 starter

I was working on my Openshift app today and without changing anything related to mongodb connection I started getting this message:
/opt/app-root/src/node_modules/mongodb/lib/server.js:242
process.nextTick(function() { throw err; })
^
Error: connect EHOSTUNREACH 172.30.173.215:27017
at Object.exports._errnoException (util.js:1020:11)
at exports._exceptionWithHostPort (util.js:1043:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
npm info lifecycle bolao_2018#0.1.0~start: Failed to exec start script
npm ERR! Linux 3.10.0-693.21.1.el7.x86_64
npm ERR! argv "/opt/rh/rh-nodejs6/root/usr/bin/node" "/opt/rh/rh-nodejs6/root/usr/bin/npm" "run" "-d" "start"
npm ERR! node v6.11.3
npm ERR! npm v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! bolao_2018#0.1.0 start: `node main`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bolao_2018#0.1.0 start script 'node main'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the bolao_2018 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node main
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs bolao_2018
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls bolao_2018
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /opt/app-root/src/npm-debug.log
The one thing different was that I saw that for some reason the mongodb service tried and failed a new deploy so I ran one manually.
I also noticed that the IP addressit tries to connect is mongodb's cluster IP but the Node IP of the current running pod is different.
Can someone help me figure out what triggered the connection to break?
Thanks
From within a given Project scope, requests directed toward a hostname of "mongodb" should be routed to the Kubernetes Service named "mongodb" (when available).
To debug this connectivity issue:
Try opening a live terminal within your front-end container using the OpenShift web console. The front-end container must be within the same Project scope as the database service
Type env to list environment variables available to the front-end. If this container was started after the creation of the "mongodb" service, configuration strings should be visible the environment
Run curl $MONGODB_SERVICE_HOST:$MONGODB_SERVICE_PORT from the live terminal to verify the availability of the mongodb service

MongoError: server sockets closed in Azure Web App

So I've deployed my express/mongodb app via git to my Azure Web App, and when I open the app's link it keeps loading and shows a black page, my routes doesn't work, but the static files load just fine.
So I went to see the log, and I got this.
D:\home\site\wwwroot\node_modules\mongodb\lib\server.js:236
process.nextTick(function() { throw err; })
^
MongoError: server 127.0.0.1:3000 sockets closed
at null.<anonymous> (D:\home\site\wwwroot\node_modules\mongodb-core\lib\topologies\server.js:330:47)
at g (events.js:260:16)
at emitTwo (events.js:87:13)
at emit (events.js:172:7)
at null.<anonymous> (D:\home\site\wwwroot\node_modules\mongodb-core\lib\connection\pool.js:105:12)
at g (events.js:260:16)
at emitTwo (events.js:87:13)
at emit (events.js:172:7)
at Socket.<anonymous> (D:\home\site\wwwroot\node_modules\mongodb-core\lib\connection\connection.js:145:12)
at Socket.g (events.js:260:16)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at TCP._onclose (net.js:469:12)
npm ERR! Windows_NT 6.2.9200
npm ERR! argv "D:\\Program Files (x86)\\nodejs\\4.2.3\\node.exe" "D:\\Program Files (x86)\\npm\\3.5.1\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v4.2.3
npm ERR! npm v3.5.1
npm ERR! code ELIFECYCLE
npm ERR! cinemat_iq#0.9.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cinemat_iq#0.9.0 start script 'node ./bin/www'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the cinemat_iq package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs cinemat_iq
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls cinemat_iq
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! D:\home\site\wwwroot\npm-debug.log
So the issues appears to be in mongodb's connection command, which I currently have it as
mongoose.connect('mongodb://127.0.0.1:3000/myapp');
I've tried changing to localhost instead of 127.0.0.1, and tried a different port, all resulted the same error.
After some googling/stackoverflowing, it appears that there's a 'lock file' in mongodb that I need to remove, then repair/restart the mongodb service.
The problem is that I can't find this file using Azure Console (which is Windows based), and I couldn't run any mongo or mongod command (it is not recognized as an internal or external command).
So what can I do to get my app to work on Azure?
As I know, there are not any databases supplied directly on Azure WebApps. So the issue was caused by no mongodb instance on the address localhost or 127.0.0.1 of your webapp, not the MongoDB connection string incorrect.
You can try to create an instance of MongoDB on Azure, and copy the connection string to change the code mongoose.connect('<the remote connection string>').
As reference, you can refer to the doc Announcing New MongoDB Instances on Microsoft Azure to know MongoDB on Azure and how to get started.
I don`t think there is local mongoDB in Azure App Service environment, try to change to connect to a remote database (e.g host your mongoDB on an Azure Virtual Machine) should fix your issue.
You can follow this post to:
create a mongoDB instance on mongolab(which is supervised by Azure)
setup your nodejs env variable in your Azure web app setting
reference the env variable in your nodejs code to connect to your mongoDB
All in QuickStart section

Hack.chat on my public IP

So, I found this cool chat some days ago ;
https://github.com/AndrewBelt/hack.chat
I managed to install it and everything is working.
The server is at 127.0.0.1:6060 and the client ( running through http-server is at 0.0.0.0:8080.
So I ran it and locally, it works.
So I was wondering what about making this chat public all over Internet using my public IP ?
Go to config.js
Change host to my public IP xx.xxx.xx.x
Then I tried to launch the server using node server.js and here the problem start !
root#user:~/hack.chat# npm start
hack.chat#1.0.0 start /root/hack.chat
node server.js
Started server on 88.169.22.4:6060
events.js:85
throw er; // Unhandled 'error' event
^
Error: listen EADDRNOTAVAIL
at exports._errnoException (util.js:746:11)
at Server._listen2 (net.js:1139:19)
at listen (net.js:1182:10)
at net.js:1280:9
at dns.js:85:18
at process._tickCallback (node.js:355:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3
npm ERR! Linux 3.19.0-22-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start"
npm ERR! node v0.12.7
npm ERR! npm v2.11.3
npm ERR! code ELIFECYCLE
npm ERR! hack.chat#1.0.0 start: node server.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hack.chat#1.0.0 start script 'node server.js'.
npm ERR! This is most likely a problem with the hack.chat package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node server.js
npm ERR! You can get their info via:
npm ERR! npm owner ls hack.chat
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /root/hack.chat/npm-debug.log
Here is the npm-debug.log file output ;
http://pastebin.com/a1N6NVkt
I searched what this problem could be, I saw some people sayin' that some process are launched on the same port but when I do a fuser 6060/tcp or fuser 8080/tcp, it show me that no process are currently running on these ports.
--
EDIT: With what I found on the web, this error is from the config.json file. I can't provide my remote address as server but don't know how to fix it
Thanks in advance.
The IP address 0.0.0.0 means that the port will be bound to accept connections from any source address. In other words, the configuration by default allows hack.chat to be used from any IP address. If http-server (or any other static file HTTP server) is also bound to 0.0.0.0, then both the static files and the WebSocket connection will be available to the public.
Problem solved !
The problem was that I didn't opened the 6060 port..
I'm really stupid lol
For the future ones who got the same problem just do this :
Redirection from port 80 to port 8080
Open the port 6060
Set the http-server and the server with IP : 0.0.0.0
And everything should works.
Thanks for the ones who helped me <3

Cannot Connect to MongoDB with Bitnami MEAN STACK using Mongoose

I purchased the MEAN tech stack from AWS (Bitnami to be specific) and have been eagerly trying to learn how to deploy my first node app. However, I have been hitting so many walls with actually getting my mongo connection to work.
I have read documentation and tried various recipes to fix the issue below
The root admin password has been reset. Here is the proof that I am using the correct pair of username and password
> bitnami#ip-172-31-43-127:~/edupal$ sudo mongo admin --username root --password
pwdremoved
MongoDB shell version: 3.0.3
connecting to: /opt/bitnami/mongodb/tmp/mongodb-27017.sock:27017/admin
Server has startup warnings:
2015-06-09T20:11:33.967+0000 I CONTROL [initandlisten]
2015-06-09T20:11:33.967+0000 I CONTROL [initandlisten] ** NOTE: This is a 32 bi
t MongoDB binary.
2015-06-09T20:11:33.967+0000 I CONTROL [initandlisten] ** 32 bit builds a
re limited to less than 2GB of data (or less with --journal).
2015-06-09T20:11:33.967+0000 I CONTROL [initandlisten] ** See http://doch
ub.mongodb.org/core/32bit
2015-06-09T20:11:33.967+0000 I CONTROL [initandlisten]
> show dbs
admin 0.078GB
local 0.078GB
users 0.078GB
> use users
switched to db users
> db.myCollection.find()
{ "_id" : ObjectId("5578c11040a096b7fef84aad"), "name" : "Bill", "score" : "9" }
So far, I believe I am in good standing in terms of credentials. Here is how I am connecting to my database
// Connect to MongoDB
mongoose.createConnection('mongodb://root:pwdremoved#/opt/bitnami/mongodb/tmp/
mongodb-27017.sock/admin');
mongoose.connection.once('open', function() {
// Load the models.
app.models = require('./models/index');
// Load the routes.
var routes = require('./routes');
_.each(routes, function(controller, route) {
app.use(route, controller(app, route));
});
console.log('Listening on port 3000...');
app.listen(8080);
});
I followed the tutorial here
and I keep getting this error
bitnami#ip-172-31-43-127:~/edupal$ npm start
> app#0.0.0 start /home/bitnami/edupal
> node ./bin/www
events.js:85
throw er; // Unhandled 'error' event
^
Error: failed to connect to [/opt/bitnami/mongodb/tmp/mongodb-27017.sock:27017]
at null.<anonymous> (/home/bitnami/edupal/node_modules/mongoose/node_modules
/mongodb/lib/mongodb/connection/server.js:555:74)
at emit (events.js:118:17)
at null.<anonymous> (/home/bitnami/edupal/node_modules/mongoose/node_modules
/mongodb/lib/mongodb/connection/connection_pool.js:150:15)
at emit (events.js:110:17)
at Socket.<anonymous> (/home/bitnami/edupal/node_modules/mongoose/node_modul
es/mongodb/lib/mongodb/connection/connection.js:534:10)
at Socket.emit (events.js:107:17)
at net.js:459:14
at process._tickCallback (node.js:355:11)
npm ERR! Linux 3.13.0-53-generic
npm ERR! argv "/opt/bitnami/nodejs/bin/.node.bin" "/opt/bitnami/nodejs/bin/npm"
"start"
npm ERR! node v0.12.4
npm ERR! npm v2.11.1
npm ERR! code ELIFECYCLE
npm ERR! app#0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app#0.0.0 start script 'node ./bin/www'.
npm ERR! This is most likely a problem with the app package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get their info via:
npm ERR! npm owner ls app
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/bitnami/edupal/npm-debug.log
I am not sure what I am doing wrong and have tried many variations of connecting to MongoDB....I've been stuck for two days now.
Bitnami developer here.
You posted that you can connect to the admin database using the root user
bitnami#ip-172-31-43-127:~/edupal$ sudo mongo admin --username root
--password pwdremoved MongoDB shell version: 3.0.3 connecting to: /opt/bitnami/mongodb/tmp/mongodb-27017.sock:27017/admin
but later you tried to connect to the "indexes" database
mongoose.createConnection('mongodb://root:pwdremoved#/opt/bitnami/mongodb/tmp/mongodb-27017.sock/indexes');
Is that database created? You can check the created databases with this command:
show dbs
If you want to use the admin database you will need to use this line:
mongoose.createConnection('mongodb://root:pwdremoved#/opt/bitnami/mongodb/tmp/mongodb-27017.sock/admin');
You could check this guide to learn how to create a database and grant privileges to a new user if you don't want to use the root user and the admin password.
https://wiki.bitnami.com/Components/mongoDB#How_to_create_a_database_for_a_custom_application.3f
I installed Meanstack 3.0.3-0 and I followed the tutorial in our wiki about how to create a sample TODO list and everything works fine. You can check it the following link.
https://wiki.bitnami.com/index.php?title=Infrastructure_Stacks/BitNami_MEAN_Stack_(MongoDB%2C_Express%2C_Angular%2C_Node.js)#How_to_create_a_sample_TODO_list_project_with_MEAN.3f
I hope this helps.

Resources