Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

How to print console without trailing newline in Node.js ?

  • Difficulty Level : Easy
  • 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:




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

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:




// 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");

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 :