Categories
JavaScript Answers

How to print to the console without a trailing newline with Node.js?

Spread the love

Sometimes, we want to print to the console without a trailing newline with Node.js.

In this article, we’ll look at how to print to the console without a trailing newline with Node.js.

How to print to the console without a trailing newline with Node.js?

To print to the console without a trailing newline with Node.js, we can use the process.stdout.write method.

For instance, we write

process.stdout.write(`Downloading ${data.length} bytes\r`);

to print Downloading ${data.length} bytes\r.

The \r character lets us overwrite the last line that was printed with new text that we print with process.stdout.write.

Conclusion

To print to the console without a trailing newline with Node.js, we can use the process.stdout.write method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *