Hi, I am using the basic scripts for connecting my postgresql database. However I keep running into this error and can’t figure out what the issue is.
Error:
[Error] this._connectionCallback is not a function
Code snippet below:
function create(user, callback) {
const bcrypt = require('bcrypt');
const { Client } = require("pg");
const conString = new Client({
user: 'postgres',
host: '**',
database: '**',
password: '**',
port: **,
});
conString.connect(conString, function (err, client, done) {
if (err) return callback(err);
bcrypt.hash(user.password, 10, function (err, hashedPassword) {
if (err) return callback(err);
const query = 'INSERT INTO users(email, password) VALUES ($1, $2)';
client.query(query, [user.email, hashedPassword], function (err, result) {
// NOTE: always call `done()` here to close
// the connection to the database
done();
return callback(err);
});
});
});
}
For additional context here are my logs:
11:08:35 AM:
{ “code”: 500, “error”: “Script generated an unhandled asynchronous exception.”, “details”: “TypeError: this._connectionCallback is not a function”, “name”: “TypeError”, “message”: “this._connectionCallback is not a function”, “stack”: “TypeError: this._connectionCallback is not a function\n at Client._handleReadyForQuery (/data/_verquire/_node16/pg/8.7.1/node_modules/pg/lib/client.js:279:14)\n at Connection.emit (node:events:527:28)\n at Connection.emit (node:domain:537:15)\n at /data/_verquire/_node16/pg/8.7.1/node_modules/pg/lib/connection.js:114:12\n at Parser.parse (/data/_verquire/_node16/pg/8.7.1/node_modules/pg-protocol/dist/parser.js:40:17)\n at Socket. (/data/_verquire/_node16/pg/8.7.1/node_modules/pg-protocol/dist/index.js:11:42)\n at Socket.emit (node:events:527:28)\n at Socket.emit (node:domain:537:15)\n at addChunk (node:internal/streams/readable:315:12)\n at readableAddChunk (node:internal/streams/readable:289:9)” }
11:08:35 AM:
Code generated an uncaught exception: TypeError: this._connectionCallback is not a function at Client._handleReadyForQuery (/data/_verquire/_node16/pg/8.7.1/node_modules/pg/lib/client.js:279:14) at Connection.emit (node:events:527:28) at Connection.emit (node:domain:537:15) at /data/_verquire/_node16/pg/8.7.1/node_modules/pg/lib/connection.js:114:12 at Parser.parse (/data/_verquire/_node16/pg/8.7.1/node_modules/pg-protocol/dist/parser.js:40:17) at Socket. (/data/_verquire/_node16/pg/8.7.1/node_modules/pg-protocol/dist/index.js:11:42) at Socket.emit (node:events:527:28) at Socket.emit (node:domain:537:15) at addChunk (node:internal/streams/readable:315:12) at readableAddChunk (node:internal/streams/readable:289:9)