3

I know that node writes to stderr if there is an uncaught exception:

https://nodejs.org/api/process.html#process_event_uncaughtexception

or if it encounters a console.error('some error yo');

https://nodejs.org/api/console.html#console_console_error_data_args

But in what other contexts would node write to stderr? I'm wondering would a throw new Error() cause node to write the error to stderr or a unknown rangeError or do those just get written to stdout? I can't find confirmation either way of this in the node docs.

Mike Rifgin
  • 10,409
  • 21
  • 75
  • 111
  • You could try these things directly yourself fairly easily, but technically anything can write directly to process.stderr, so any libraries or app code could write there. – Joseph Reeve Apr 20 '18 at 10:26
  • Ok great. How can I monitor that something has been written to `stderr`? I understand that anything "can" write to stderr but what I'm after is info on whether Js errors (syntax, range, type for example) and errors generated via `throw new error` get written to `stderr` – Mike Rifgin Apr 20 '18 at 10:28
  • I suppose you could monitor process.stderr with `process.stderr.on('data', ...);`, but you can just check what goes to stderr from where you execute it? As per https://stackoverflow.com/questions/25331205/bash-print-stderr-only-not-stdout You could try `node index.js > /dev/null` – Joseph Reeve Apr 20 '18 at 10:35

0 Answers0