Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between error, stderr, stdout in node

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.

like image 200
haeminish Avatar asked Apr 15 '15 01:04

haeminish


People also ask

What is the difference between stdout and stderr?

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.

What is stdout and stderr Nodejs?

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.

How many types of errors are there in node JS?

In general, Node. js errors are divided into two distinct categories: operational errors and programmer errors.

What is error in Nodejs?

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 .


2 Answers

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:)

like image 177
Kewei Qu Avatar answered Sep 30 '22 18:09

Kewei Qu


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

like image 41
tpie Avatar answered Sep 30 '22 18:09

tpie