I am using node.js and want to handle error messages. What are the differences between erro, stderr, stdout?
When scripting shell, I redirected stderr and found useful error message and it solved the problem.
I am not clear about the concept of what kind of outputs computer have either. Can anyone explain in a comprehensive way?
Thanks.
stdout − It stands for standard output, and is used to text output of any command you type in the terminal, and then that output is stored in the stdout stream. stderr − It stands for standard error. It is invoked whenever a command faces an error, then that error message gets stored in this data stream.
process. stdout (1): The standard output stream, which is a source of output from the program. process. stderr (2): The standard error stream, which is used for error messages and diagnostics issued by the program.
In general, Node. js errors are divided into two distinct categories: operational errors and programmer errors.
An error in Node. js is any instance of the Error object. Common examples include built-in error classes, such as ReferenceError , RangeError , TypeError , URIError , EvalError , and SyntaxError .
It is actually an interesting question. You would probably get more answers if you format the title of your question like this -- Node JS difference between error, stderr, and stdout.
I won't repeat the difference between stdout and stderr, as it is answered previously.
However, the difference between error and stderr is not that easily distinguished.
Error is an error object created by Node JS because it is having a problem executing your command. See more here
Stderr is a standard output stream that happens because something is wrong during execution -- that is Node JS has no trouble executing your command, it is your command itself throws the error.
Let me know if this is clear, otherwise, I'm happy to throw in an example:)
stderr
and stdout
are streams. Writing to console will log both streams. Apparently the distinction exists between them so we that if we want to (for example) redirect certain data elsewhere, we have the ability to be selective.
You may find the following article helpful.
http://www.jstorimer.com/blogs/workingwithcode/7766119-when-to-use-stderr-instead-of-stdout
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With