Related Articles

Related Articles

How to print console without trailing newline in Node.js ?
  • Last Updated : 26 Feb, 2020

In Node.js, console.log() method is used to display the message on the console. By default, the console.log() method prints on console with trailing newline.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the   
// console.log() Method
  
console.log("Welcome to GeeksforGeeks! ");
console.log("A computer science portal for geeks");

chevron_right


Output:

Welcome to GeeksforGeeks!
A computer science portal for geeks

In the above example, Welcome to GeeksforGeeks! printed on first line and A computer science portal for geeks printed on second line.
But sometimes we may need to print the console without trailing newline. In that case, we can use process.stdout.write() method to print to console without trailing newline.

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the   
// process.stdout.write() Method
  
process.stdout.write("Welcome to GeeksforGeeks! ");
process.stdout.write("A computer science portal for geeks");

chevron_right


Output:

Welcome to GeeksforGeeks! A computer science portal for geeks

Note: The process object is global so it can be used without using require() method.

My Personal Notes arrow_drop_up
Recommended Articles
Page :