dwyl / hapi-postgres-connection

:zap: Creates a PostgreSQL Connection (Pool) available anywhere in your Hapi App
GNU General Public License v2.0
40 stars 13 forks source link

hapi-postgres-connection error #34

Closed xplorer1 closed 6 years ago

xplorer1 commented 7 years ago

Hello. I'm new to web development in general, and I started with nodejs. I'm using hapijs to generate the server. I'm also using postgresql 4 to design my database.

Finally, I use hapi-postgres-connection plugin to connect to the database.

The first few times I tried it, it worked.

I decided to use it with angularjs that I just started learning. Then it refused to work. This the code.

**const hapi_module = require('hapi'); const server = new hapi_module.Server();

server.connection({ port:8080, host:'localhost', routes: {cors:true} });

server.register ({ register: require('hapi-postgres-connection') }, function (error) { if (error) { throw error; } });

server.route({ path:'/postgresCountry', method: 'GET', handler: function(request, reply) { let email = 'postgres@postgres.net'; let select = 'SELECT * FROM country'; request.pg.client.query(select, function(error, result) { console.log(error, result.rows); console.dir(error); return reply(result.rows); }); } });**

The above is the hapijs code that is supposed to allow me access to the database. For some reason, it returns the following error:

**Server running at: http://localhost:8080

assert.js:81 throw new assert.AssertionError({ ^ AssertionError: hapi-postgres-connectionERROR Connecting to PostgreSQL! at C:\webstorm_nodejs\node_modules\hapi-postgres-connection\index.js:15:3 at client.connect (C:\webstorm_nodejs\node_modules\pg-pool\index.js:219:9) at Connection.connectingErrorHandler (C:\webstorm_nodejs\node_modules\pg\lib\client.js:123:14) at emitOne (events.js:96:13) at Connection.emit (events.js:191:7) at Socket. (C:\webstorm_nodejs\node_modules\pg\lib\connection.js:71:10) at emitOne (events.js:96:13) at Socket.emit (events.js:191:7) at emitErrorNT (net.js:1279:8) at _combinedTickCallback (internal/process/next_tick.js:80:11)**

I really don't know why this error is thrown. I would really appreciate any help!

xplorer1 commented 7 years ago

Please, this is my first time using this forum. I really don' t know how to edit posts. I did't know it would come out this bad. I would do better next time.

alina-dumitrache commented 6 years ago

Hi,

Did you manage to fix the issue? Your connection might require SSL, I have proposed this solution for adding the ability to use it in connections: https://github.com/dwyl/hapi-postgres-connection/pull/35.

nelsonic commented 6 years ago

@alla91 thanks again for your PR. it has been merged and the latest version on NPM v6.5.0 contains your optional SSL parameter. 🎉

@Xanthosis12 please re-test and confirm it works as expected. thanks.