Is there a Node.js console.log length limit?

后端 未结 2 999
野性不改
野性不改 2021-02-14 17:03

Is there a limit the length of console.log output in Node.js? The following prints numbers up to 56462, then stops. This came up because we were returning datasets from MySQL

2条回答
  •  花落未央
    2021-02-14 17:37

    Have you tried writing that much on a machine with more memory?
    According to Node source code console is writing into a stream: https://github.com/joyent/node/blob/cfcb1de130867197cbc9c6012b7e84e08e53d032/lib/console.js#L55
    And streams may buffer the data into memory: http://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback

    So if you put reeeaally a lot of data into a stream, you may hit the memory ceiling. I'd recommend you split up your data and feed it into process.stdout.write method, here's an example: http://nodejs.org/api/stream.html#stream_event_drain

提交回复
热议问题