Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like client (pg.Client) is declared outside the scope of a request, this is probably your issue. It's hard to tell from the code snippet, but it looks like you might have issues with scoping and how async callback control flow works in general, e.g. calling res.end() while callbacks are still in the IO queue. This is totally legal with node, just not sure that is your intent.</p> <p>It is preferred to use pg.connect which returns a client. see <a href="https://github.com/brianc/node-postgres/wiki/pg" rel="noreferrer">https://github.com/brianc/node-postgres/wiki/pg</a></p> <pre><code>var pg = require('pg'); var server = http.createServer(function (req, res) { var url = parse(req.url); if (url.pathname =='/'){ (...) }else{ var slash_index = url.pathname.indexOf('/',1); var command = url.pathname.slice(1,slash_index); if (command =='restart'){ res.write('restarting server please wait'); } else if (command == 'drop-db'){ console.log('drop-db'); pg.connect(conString, function(err, client) { console.log('connect'); var query = client.query("select datname from pg_database;", function(err, result) { if (err) throw err; console.log('callback'); }); query.on('end', function() { console.log('close'); // client.end(); -- not needed, client will return to the pool on drain }); }); } else{ res.write('unknown command : '+ command); } // these shouldn't be here either if you plan to write to res from within the pg // callback res.write('\n'); res.end(); } }).listen(5337); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload