Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stdout flush for NodeJS?

Tags:

node.js

Is there any stdout flush for nodejs just like python or other languages?

sys.stdout.write('some data')  sys.stdout.flush() 

Right now I only saw process.stdout.write() for nodejs.

like image 706
TonyTakeshi Avatar asked Sep 20 '12 10:09

TonyTakeshi


People also ask

What is flush stdout?

stdout. flush() forces it to “flush” the buffer, meaning that it will write everything in the buffer to the terminal, even if normally it would wait before doing so.

Can you console log in node JS?

js provides a console module which provides tons of very useful ways to interact with the command line. It is basically the same as the console object you find in the browser. The most basic and most used method is console. log() , which prints the string you pass to it to the console.

Why do you need to flush stdout?

Use the fflush Function to Flush stdout Output Stream in C As a result, there are buffers maintained by the C library for handling the input/output operations when using the stdio function calls. If the user needs to force writing to kernel buffers, it needs to flush the given stream provided by the fflush function.


1 Answers

process.stdout is a WritableStream object, and the method WritableStream.write() automatically flushes the stream (unless it was explicitly corked). However, it will return true if the flush was successful, and false if the kernel buffer was full and it can't write yet. If you need to write several times in succession, you should handle the drain event.

See the documentation for write.

like image 171
jonvuri Avatar answered Oct 08 '22 16:10

jonvuri