PostgreSQL keep failing password auth in Node.js - javascript

Seems like There's something wrong with connect function.
config.DATABASE_URL is initialized using environment export DATABASE_URL=postgres://bustabit:1234#localhost/bustabitdb
function connect(callback) {
return pg.connect(config.DATABASE_URL, callback);
}
error: password authentication failed for user "bustabit"
at Connection.parseE (/home/bobbysun/busta/bustabit-gameserver/node_modules/pg/lib/connection.js:526:11)
It's kind of weird that It fails just like in connect function when I try to login psql in shell like:
psql -d bustabitdb -U bustabit
psql: FATAL: Peer authentication failed for user "bustabit"
but This one works:
psql bustabit -h 127.0.0.1 -d bustabitdb
Password for user bustabit:
psql (9.3.16)bustabitdb=>
Does anybody have any idea why this happens? I think I should change DATABASE_URL but I'm pretty new to postgreSQL so I have no idea what to change.
UPDATE: upgrading pg module to latest version resolves this problem.

Related

Raspberry Pi 4 To A Remote MySql: Stderr : /bin/sh: 1: mysql: not found

In continuation to my previous question here (Fully details: connect Raspberry Pi 4 to a remote MySql database located on a server), I have been digging to find out what causing the error and why my Raspberry Pi 4 fails to connect to a remote MySql database through JavaScript but, it makes a perfect connection through Python script.
I executed the following shelljs.exec() command to know the cause (inspired from: how to run node shelljs in sync mode and get stdout and stderr) and I got the following output. I need help to know what this error mean and I need to do fix it.
My code and output:
>> var shell = require('shelljs');
>> const { stdout, stderr, code } = shell.exec(command, { silent: true })
>> console.log("Stdout: "+stdout+", Stderr: "+stderr+", Code: "+code)
# Output is
>> Stdout: , Stderr: /bin/sh: 1: mysql: not found, Code: 127
My understanding from above is, there is no output. But there is an error message called /bin/sh: 1: mysql: not found and error code is 127. I appreciate your help to understand what this error mean and what I need to do? Does it telling that my Raspberry Pi 4 is missing something, so it fails to connect to the remote MySql through JavaScript?
Update:
Based on #Mark Setchell suggestion below:
I have installed the MySql on the RPi by referring https://pimylifeup.com/raspberry-pi-mysql/ The code is sudo apt install mariadb-server
#Mark Setchell suggestions: Here is the terminal response
pi#raspberrypi:~ $ /usr/bin/mysql -u fieldArduinoYUN -h aa.bb.cc.dd -p abcdf -e "use field_data; SELECT product FROM product_list WHERE product_id = 123;"
Enter password:
ERROR 1044 (42000): Access denied for user 'fieldArduinoYUN'#'%' to database 'abcdf'
pi#raspberrypi:~ $
Summarising the exchanges from the comments, there were the following issues and solutions.
The following error means that the shell (bash/dash/ash etc) was unable to find the mysql command:
/bin/sh: 1: mysql: not found
This normally results from the PATH variable not being set to tell the shell where mysql is located in the filesystem.
It transpired that, in this case, the reason was that the mysql client was not installed. OP had thought that installing a Python module would provide a command-line MySQL client too.
The solution was to install the MYSQL client tools.
The second issue was that the password for the mysql client tool wasn't being provided correctly which resulted in:
ERROR 1044 (42000): Access denied
This can be solved by providing the password immediately following the -p option and without a space like this:
/usr/bin/mysql -u USER -h aa.bb.cc.dd -pPASSWORD -e "SOMECOMMAND"

ntlm auth failed with error STATUS_USER_SESSION_DELETED

I am using a Windows server to manage our files(read, write). To connect to that server I am using SMB2 npm module https://www.npmjs.com/package/smb2. Internally, this module uses the ntlm method to authenticate. While authenticating, I am getting the error STATUS_USER_SESSION_DELETED. Authentication process is given below:
it sends NEGOTIATE command
SESSION_SETUP command
SESSION_SETUP command with SessionId (this is where the error is thrown)
TREE_CONNECT command
There is already open issues regarding same with Repo, so, waiting for that as well but any lead would be helpful

.env process.env isn't working with DocuSign docusignAPI using node.js example

I'm using the example from docusign at https://github.com/docusign/qs-02-node-send-envelope ,
and have configured the index.js file the ACCESS_TOKEN, ACCOUNT_ID, USER_FULLNAME and USER_EMAIL it worked fine. But when I configure the .env file it doesn't work.
I did install $ npm install and $ npm install dotenv.
ACCESS_TOKEN=eyJ0eXMtNjg5ODEyMjAzMzETtl0--w
ACCOUNT_ID=123456
USER_FULLNAME="Larry Smith"
USER_EMAIL=myemail#mail.com
this is the localhost answer
API problem
Status code 401
Error message:
{
"errorCode": "AUTHORIZATION_INVALID_TOKEN",
"message": "The access token provided is expired, revoked or malformed."
}
with the console.log(accessToken) it replies ACCESS_TOKENinstead of eyJ0eXMtNjg5ODEyMjAzMzETtl0--w
Need help to set up process.env with docusign or docusignapi.
From dotenv docs:
As early as possible in your application, require and configure dotenv.
require('dotenv').config()
You may turn on logging to help debug why certain keys or values are not being set as you expect.
require('dotenv').config({ debug: process.env.DEBUG })

How to authenticate to connect to database in Postgres?

I'm trying to connect to a postgres database from outside the psql command line (so before doing sudo -u postgres psql) but it seems that I'm not able to pass authentication. Here's the error after I try to run a script that connects to that database from the command line:
error: password authentication failed for user "bobby"
"bobby" is my Operating System user name, I noticed that the postgres database contains a superuser called postgres though
I'm new to all this postgres stuff so I'm a bit confused why it's trying to authenticate using my OS user name rather than my psql user name, or rather how I would go about authenticating using the psql user name rather than my OS user name because I know they're separate from each other.
Any help would be appreciated. Thanks in advance.
You need to add your system user name to posgres database
$ psql -d template1 -U postgres
template1=# CREATE USER bobby WITH PASSWORD 'myPassword'
template1=# CREATE DATABASE mydatabase
template1=# GRANT ALL PRIVILEGES ON DATABASE mydatabase to bobby
Done and quit
Then you can access the database with
bobby=#psql mydatabase

Fail to connect Mongolab with MongodbShell

I'm trying to connect the Mongo shell with Mongolab. I am using my mongolab username and password but it is giving an error: "Failed to connect to 54.81.180.188:56789."
My userName and password is correct.
I'm using Windows 8.1
When I ping ds0-----.mongolab.com that's working fine.
C:\mongodb\bin>mongo ds0----.mongolab.com:56789/dbname -u "MyUserName" -p "MyPassword"
MongoDB shell version: 3.0.3
connecting to: ds027751.mongolab.com:56789/dbname
2015-06-05T10:55:30.019+0530 W NETWORK Failed to connect to 54.81.180.188:56789, reason: errno:10061 No connection could be made because the target machine actively refused it.
2015-06-05T10:55:30.024+0530 E QUERY Error: couldn't connect to server ds027751.mongolab.com:56789 (54.81.180.188), connection attempt failed
at connect (src/mongo/shell/mongo.js:181:14)
at (connect):1:6 at src/mongo/shell/mongo.js:181
exception: connect failed
I had the same problem, my server abruptly lost the ability to connect to MongoLab. I contacted support, who sent this reply:
Hello,
Your Experimental Sandbox plan is running MongoDB 3.0.x, which
includes changes to Mongo's authentication mechanism. This new
mechanism is supported by certain newer driver versions, as described
at
http://docs.mongodb.org/manual/release-notes/3.0-scram/#upgrade-drivers.
To connect to this database, you will need to use one of the drivers
listed at the above link.
Please let us know if you have questions about this.
Sincerely, Samson
I assume I was upgraded automatically, as I hadn't touched the server code or MongoLab in months. As an immediate fix, I just created a new db in MongoLab, which was created in mongod v2.6.9 (I don't remember seeing an option to choose the version).

Categories