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

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 w3wiki! ");
console.log("A computer science portal for Beginner");


Output:

Welcome to w3wiki!
A computer science portal for Beginner

In the above example, Welcome to w3wiki! printed on first line and A computer science portal for Beginner 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 w3wiki! ");
process.stdout.write("A computer science portal for Beginner");


Output:

Welcome to w3wiki! A computer science portal for Beginner

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