Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use PostgreSQL (pg) in the client-side (express/node.js)

I want to use PostgreSQL in the client side. is that possible? can i have this code?

in my server.js

   var pg = require('pg');

in my client side

     var conString = "postgres://postgres:pass@localhost/mydb";
     var client = new pg.Client(conString);
     client.connect();
     var query = client.query("SELECT * FROM users ");        
     query.on('row', function(row) {
             alert(row.name);
     });

i tried this code but nothing happened. though can i have a code similar to this, where i connect PostgreSQL and use queries on the client scripts.

like image 551
Jude Calimbas Avatar asked Feb 25 '12 14:02

Jude Calimbas


1 Answers

No, that's (obviously) not possible. You wouldn't want to let a client access your database directly anyway. Besides that, even though you use JS on both the client and server side it's not different from what happens if you use e.g. PHP or Python on the server - the only communication between it is possible via AJAX and regular http requests.

like image 195
ThiefMaster Avatar answered Sep 30 '22 03:09

ThiefMaster