- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between console.log and process.stdout.write in NodeJS
Both the methods – console.log and process.stdout.write have a basic definition to write or print the statements on the console. But, there is a slight difference in the way they execute these tasks. Internally, console.log implements process.stdout.write which itself is a buffer stream that will be used to directly print statements on your console.
|It continuously prints information as retrieved from the stream without adding any new line.||It first prints the information being retrieved and then adds a new line. Then it will go to retrieve the second set of statements to print.|
|The process.stdout.write method takes only string as paramter. Other datatypes passed will result in a type error.||It can take any type of input parameter.|
|We will get a weird characted if we don't put the breakline at the end.||We donot need any break line here as the text is already formatted, also the character disappears itself.|
|It is used for printing patterns, since it does not adds a new line.||It is used when we require a new line after printing a statement.|
|It cannot be used to print multiple strings at a time.|
For example, process.stdout.write("Hello", "World"); will throw a type error as it is not a string anymore.
|We can write multiple strings using this method. For example, console.log("Hello", "World"); will print Hello World in console.|
|This method cannot associate two string types. For example,|
process.stdout.write("Hello %s", "All"); will throw a type error/
|This method can be used for making associations.|
For example, console.log("Hello %s", "All"); will print Hello All on the console.
<script> // For process.stdout process.stdout.write("Hello"); process.stdout.write("World"); process.stdout.write("!!!"); </script>
<script> // For process.stdout console.log("Hello"); console("World"); console.log("!!!"); </script>
Hello World !!!
- Related Articles
- Difference between NodeJS and AngularJS
- Difference between NodeJS and ReactJS
- Difference between process.cwd & _ _dirname in NodeJS
- How to get Exception log from a console and write it to external file in java?
- Log error to console with Web Workers in HTML5
- Difference between Process and Thread
- Difference Between Product and Process
- Difference Between Program and Process
- How to write Stdout to a file with colors?
- Difference between Product and Process in Software development
- Understanding stdin, stderr and stdout in Linux
- What is the difference between 'log' and 'symlog' in matplotlib?
- Difference between Write-Output and Write-Host command in PowerShell?
- What is the difference between process and program?
- Write the difference between dividend and growth.