New Text Styling Feature in Version Node.js 21.7.0

Node.js has introduced a new feature to easily format and style your text in the console.

If you've tried styling your output to make your logs look good, you might have reached for something like Chalk.

Released on March 6, 2024, version 21.7.0 introduces a new util function called styleText, making it easy to add color and style to their console output.

The styleText function allows for text styling by accepting two parameters: a format and the text to be styled.

This innovation builds upon the existing util.inspect.colors framework, expanding its capabilities to include a variety of colors such as red and blue and text emphasis options like italic and bold.

Here's a quick example of how to use this new feature:

const { styleText } = require('node:util');
const message = styleText('blue', 'I am BLUE!!!');
const errorMessage = styleText('red', 'Error!');
console.log(message);
console.log(errorMessage);

Pretty cool! I love any additions like this that can remove some of my dependencies.

Nodejs
Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses: Lead Developer, Software Architect, Product Manager, CTO, and now happily a Founder.

Loading

Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.