question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with pg-query-stream dest.on is not a function

See original GitHub issue

Using the example code in pg-query-stream, you get an error that dest.on is not a function.

Here is my code:

const pg = require('pg')
const QueryStream = require('pg-query-stream')

let p = new pg.Pool({host: 'localhost', user: 'postgres', database: 'postgres'})
p.connect((err, client, done) => {
   if (err) throw err;
   const query = new QueryStream('SELECT * FROM generate_series(0, $1) num', [1000000])
   const stream = client.query(query)
   //release the client when the stream is finished
   stream.on('end', done)
   stream.pipe(console.log)
}

and I get the following error:

Uncaught TypeError: dest.on is not a function
    at PgQueryStream.Readable.pipe (_stream_readable.js:714:8)
    at PendingItem.callback (repl:7:10)
    at Pool._acquireClient (/home/nhumrich/project/node_modules/pg-pool/index.js:267:21)
    at /home/nhumrich/project/node_modules/pg-pool/index.js:230:21
    at Connection.<anonymous> (/home/nhumrich/project/node_modules/pg/lib/client.js:234:7)
    at Object.onceWrapper (events.js:411:26)
    at Connection.emit (events.js:316:22)
    at Connection.EventEmitter.emit (domain.js:545:15)

pg-query-stream version 3.0.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brianccommented, Jan 15, 2020

You can’t pipe a stream to console.log - you’ll want to pipe to process.stdout or process.stderr - console.log is not a writable stream.

If it makes you feel better I’ve piped things to console.log many a time & got this error. 🤦‍♂

0reactions
AlexGalayscommented, Feb 1, 2021

That one caught me good as it’s both wrong in the documentation and TS typings.

Only to then find out pg-query-stream is outdated and doesn’t work anyway:

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does this mean: TypeError: dest.on is not a function
1 · If the error mentions code that is not present in the code you written it probably means you passed some function...
Read more >
NodeJS Streams and E2E streaming from Postgres using pg ...
In this demo, we'll use NodeJS and pg-query-stream to implement end-to-end streaming from Postgres to the HTTP client.
Read more >
Stream every row coming from a Postgres function
On the client i am trying to use a QueryStream from the pg-query-stream package: pool.connect((err, client, done) => { if (err) throw err...
Read more >
[Solved]-TypeError: dest.on is not a function-node.js
... dest.on is not a function-node.js. Search. score:1. Accepted answer. Yeah I asked this question on Node.js help https://github.com/nodejs/help/issues/ ...
Read more >
Dest.On Is Not A Function In Gulp Tasks - ADocLib
Many webbased projects feature frontend JavaScript files that are This would serve minified files to our client but it would not solve the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found