Postresql not connecting to heroku - javascript

im using heroku to host my site however it keeps spitting out the same error which is
2018-05-06T19:28:52.212104+00:00 app[web.1]:AssertionError [ERR_ASSERTION]: false == true
2018-05-06T19:28:52.212106+00:00 app[web.1]:at Object.exports.connect (_tls_wrap.js:1036:3)
2018-05-06T19:28:52.212107+00:00 app[web.1]: at Socket. (/app/node_modules/pg/lib/connection.js:94:23)
2018-05-06T19:28:52.212109+00:00 app[web.1]:at Object.onceWrapper (events.js:315:30)
2018-05-06T19:28:52.212110+00:00 app[web.1]:at emitOne (events.js:116:13)
2018-05-06T19:28:52.212112+00:00 app[web.1]: at Socket.emit (events.js:211:7)
2018-05-06T19:28:52.212113+00:00 app[web.1]:at addChunk (_stream_readable.js:263:12)
2018-05-06T19:28:52.212115+00:00 app[web.1]:at readableAddChunk (_stream_readable.js:250:11)
2018-05-06T19:28:52.212116+00:00 app[web.1]:at Socket.Readable.push (_stream_readable.js:208:10)
2018-05-06T19:28:52.212118+00:00 app[web.1]: at TCP.onread >>(net.js:607:20)
this is how im connecting (taken straight off of herokus website)
const { Client } = require("pg");
const router = express.Router();
const pool = new Client({
connectionString: process.env.DATABASE_URL,
ssl: true,
});
pool.connect();
I found out what the error was:
the error was that i did not have a db create. i decided to use elephantSQL and from their i connected to elephantSQL with pgadmin and recreated my database. it works perfect now
to see how this works see : https://www.elephantsql.com/docs/pgadmin.html
im more than happy to answer some questions

OK, this isn't really a solution but it might help you out. This happens to me on node 8 (and 10) but when I downgraded to node 7 it seems to work fine. I'll be watching this post to see if someone comes up with a better fix.

Related

Mongodb connection suddenly stopped working with "Bad Auth" error

So mongoose was working just fine for more than 2 months, but suddenly crashed with this error
/home/container/node_modules/mongodb/lib/cmap/connection.js:210
callback(new error_1.MongoServerError(document));
^
MongoServerError: bad auth : Authentication failed.
at Connection.onMessage (/home/container/node_modules/mongodb/lib/cmap/connection.js:210:30)
at MessageStream.<anonymous> (/home/container/node_modules/mongodb/lib/cmap/connection.js:63:60)
at MessageStream.emit (node:events:527:28)
at processIncomingData (/home/container/node_modules/mongodb/lib/cmap/message_stream.js:132:20)
at MessageStream._write (/home/container/node_modules/mongodb/lib/cmap/message_stream.js:33:9)
at writeOrBuffer (node:internal/streams/writable:390:12)
at _write (node:internal/streams/writable:331:10)
at MessageStream.Writable.write (node:internal/streams/writable:335:10)
at TLSSocket.ondata (node:internal/streams/readable:777:22)
at TLSSocket.emit (node:events:527:28) {
ok: 0,
code: 8000,
codeName: 'AtlasError',
[Symbol(errorLabels)]: Set(1) { 'HandshakeError' }
}
Anyone knows what is the issue?
My IP is configured as access from anywhere correctly
Using connection to application, my uri is well configured and copy pasted to my project, and again the connection was perfect for 2months but stopped out of nowhere

Why I get Access Denied error from Loopback4 while able to connect from MySql workbench using same credentials

I am trying to run todo list example in loopback 4. I use MySql as the backend db on a different server. The problem I am facing is while I could connect to the database from MySql Workbench, I get the following error when I try making the db connection from loopback 4 using the same credentials.
Any help is appreciated.
Connection fails: Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'dev1'#'%' to database 'todo'
It will be retried for the next request.
C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\sequences\Sequence.js:47
var err = new Error(code + ': ' + packet.message);
^
Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'dev1'#'%' to database 'todo'
at Handshake.Sequence._packetToError (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket.<anonymous> (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\Connection.js:91:28)
at Socket.<anonymous> (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\Connection.js:525:10)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead (internal/stream_base_commons.js:182:23)
--------------------
at Protocol._enqueue (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\Connection.js:119:18)
at Pool.getConnection (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\Pool.js:48:16)
at MySQL.connect (C:\Users\rames\GitHub\todo-list\node_modules\loopback-connector-mysql\lib\mysql.js:90:17)
at Object.initializeDataSource [as initialize] (C:\Users\rames\GitHub\todo-list\node_modules\loopback-connector-mysql\lib\mysql.js:44:28)
at DbDataSource.DataSource.setup (C:\Users\rames\GitHub\todo-list\node_modules\loopback-datasource-juggler\lib\datasource.js:513:19)
at new DataSource (C:\Users\rames\GitHub\todo-list\node_modules\loopback-datasource-juggler\lib\datasource.js:145:8)
at new DbDataSource (C:\Users\rames\GitHub\todo-list\src\datasources\db.datasource.ts:20:5)
at C:\Users\rames\GitHub\todo-list\node_modules\#loopback\context\src\resolver.ts:73:14
at Object.transformValueOrPromise (C:\Users\rames\GitHub\todo-list\node_modules\#loopback\context\src\value-promise.ts:270:12)
at Object.instantiateClass (C:\Users\rames\GitHub\todo-list\node_modules\#loopback\context\src\resolver.ts:66:35)
at C:\Users\rames\GitHub\todo-list\node_modules\#loopback\context\src\binding.ts:533:29
at Binding._getValue (C:\Users\rames\GitHub\todo-list\node_modules\#loopback\context\src\binding.ts:410:14)
at C:\Users\rames\GitHub\todo-list\node_modules\#loopback\context\src\binding.ts:305:23
at C:\Users\rames\GitHub\todo-list\node_modules\#loopback\context\src\resolution-session.ts:114:13
I noticed there was a typo in database name in the connection string. I fixed it and I am able to connect now.
#jaromanda Thank you.

MongoDb Connection Error when using Mongoose

I did not have a problem connecting to Atlas previously from my wifi at home. But I have issues at Starbucks. I have now switched to google fiber and I am getting this error.
at Pool.<anonymous> (/Users/j/Desktop/projects/templateApp/node_modules/mongodb-core/lib/topologies/server.js:431:11)
at Pool.emit (events.js:182:13)
at connect (/Users/j/Desktop/projects/templateApp/node_modules/mongodb-core/lib/connection/pool.js:557:14)
at callback (/Users/j/Desktop/projects/templateApp/node_modules/mongodb-core/lib/connection/connect.js:109:5)
at runCommand (/Users/j/Desktop/projects/templateApp/node_modules/mongodb-core/lib/connection/connect.js:129:7)
at Connection.errorHandler (/Users/j/Desktop/projects/templateApp/node_modules/mongodb-core/lib/connection/connect.js:321:5)
at Object.onceWrapper (events.js:273:13)
at Connection.emit (events.js:182:13)
at TLSSocket.<anonymous> (/Users/j/Desktop/projects/templateApp/node_modules/mongodb-core/lib/connection/connection.js:350:12)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:182:13)
at _handle.close (net.js:596:12)
at TCP.done [as _onclose] (_tls_wrap.js:383:7)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],```
I have checked my strings and they are correct.
My connection code is:
```mongoose.connect(process.env.dataBaseConnection, {
dbName: process.env.dataBaseName,
useFindAndModify: false,
useNewUrlParser: true
});```
The issue was that I needed to white list my new ip address.

In windows, stopping postgres service causes node to crash with "error : terminating connection due to administrator command"

Scenario 1: postgres service not running. node start. rest calls times out => no issues
Scenario 2: postgres service not running. node start. postgres service start. rest calls work => no issues
Scenario 3: postgres service not running. node start. postgres service start. rest calls work. postgres service stop => node crash.
Stack trace when this happens is given below:
error: terminating connection due to administrator command
at Connection.parseE (...\express.js\node_modules\pg\lib\connection.js:553:11)
at Connection.parseMessage (...\express.js\node_modules\pg\lib\connection.js:378:19)
at Socket. (...\express.js\node_modules\pg\lib\connection.js:119:22)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:594:20)
I am using Postgres Pool with the following config:
const pool = new Pool({
user: 'postgres',
host: 'localhost',
database: 'sampleDB',
password: 'password',
port: 5432,
max: 1,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
})
How do I handle this case so that node won't crash and can go back to Scenario-1 and then move to Scenario-2 ?
After going through the documentation of node-postgres(link), I figured out a way to capture this error and avoid node crash.
pool.on('error', (err, client) => {
console.log('postgres connection error : ' + err)
})
Adding the above code will allow node to handle the error and not crash.

How can I configure sails-neo4j adapter?

I'm trying to create a simple web app using sailsjs. I'd like to use a neo4j database and I've found only this adapter: https://github.com/natgeo/sails-neo4j/
I try to add the adpter configuration in connection.js using mostly of default value (as I've a default installation):
neo4jServer: {
adapter: 'sails-neo4j'
//protocol: 'http://',
//port: 7474,
//host: 'localhost',
//base: '/db/data/',
//debug: false }
and specifing it in my model.js file:
connection: 'neo4jServer',
but I've this error (not so explicit..) if I try to lift up the server (I don't have any logic yet, I only created a couple of model using api generation):
C:\WS\SAILS\testProject\node_modules\sails-neo4j\lib\connection.js:15
throw err;
^ Error
at ClientRequest.<anonymous> (C:\WS\SAILS\testProject\node_modules\sails-neo4j\node_modules\neo4j-js\lib\Neo4jApi.js:227:13)
at ClientRequest.g (events.js:260:16)
at emitOne (events.js:77:13)
at ClientRequest.emit (events.js:169:7)
at HTTPParser.parserOnIncomingClient (_http_client.js:415:21)
at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23)
at Socket.socketOnData (_http_client.js:305:20)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
at TCP.onread (net.js:523:20)
Does anyone use it? How can be configured in order to make it works? I'm using sailsjs 0.11.3
Thanks,
Michele.
If using authentication with Neo4j, be sure to specify the credentials. You can do this in the host property of the config object for the sails adapter (Neo4j uses Basic Authentication):
neo4jServer: {
adapter: 'sails-neo4j'
protocol: 'http://',
port: 7474,
host: 'username:password#localhost',
base: '/db/data/',
debug: false
}
or disable Neo4j authentication by setting dbms.security.auth_enabled=false in conf/neo4j-server.properties

Categories

Resources