385569 (5) [Avatar] Offline
Hi, I choose this course because I don't understand some functionalities of node like input and output.

I only have experience with javascript client side, and when I had an interview question that was used input, output and process.stdin, I didn't know to use.


function main (input) {
 input.split ("\n").forEach (function (n){
 console.log (n);
process.stdin.resume ();
process.stdin.setEncoding ("utf-8")
process.stdin.on ("data", function (input){
 stdin_input += input;
process.stdin.on ("end", function (){
 main (stdin_input);

What this process.stdin is? What is going on in that code?
In the test(that i failed) I had to insert my Javasrcript code inside that block and return the result of a new function in the output.
PJ Evans (4) [Avatar] Offline
In the Linux/Unix world (and to an extent, Windows too), all processes communicate using three 'streams'. 'Standard In', better known as stdin, is where the process can get its input. 'Standard Out' (stdout) is from the process to write out its results. The third, Standard Error (stderr), is a writable stream reserved for errors, which allows errors to be distinguished from actual output.

When you run any application, command-line or otherwise, you're using stdin, stdout and stderr. It's just hidden from you.

So, when we run a Node command-line app, it can ask for input from stdin (i.e. the keyboard) and writing to stdout causes text to appear on the screen.

385569 (5) [Avatar] Offline
I am starting to understand.
You explain that it's command-line, but the code with stdin and stdout was inside a webpage like an editor, if I wanna to print something in the screen where should I have to paste the code?
Inside stdout?

Thank for the explanation.
PJ Evans (4) [Avatar] Offline
The joy of stdin/out/err is that these streams can be redirected anywhere without the application needing to know about it. So, if your using a web-based system, it is listening to Node's stdout and producing the output on the webpage. So, to write out, you need to write to the stdout stream. There are many 'wrappers' that make this easy, but you always have access to
process.stdout.write('Hello, world');

In fact console.log(string) is a wrapper for this that just adds a CRLF to the end of it.
385569 (5) [Avatar] Offline
Thank you very much.

It will be have more about this in the course? Or some website I can learn more about it?
PJ Evans (4) [Avatar] Offline
stdin/out/err is more of a generic UNIX topic rather than specific to Node, so I'm not planning to go into any more depth bar that covered in unit 2. However, this is a good overview of how the system works conceptually:


385569 (5) [Avatar] Offline
Thank you.