Alex Rivera | Logout

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

Asked 2012-02-25T14:42:05.907
8

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.

Edit
Report

1 Answer

11

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.

answered 2012-02-25T14:57:36.167

Your Answer