talira

colors.js

Colours and styles for Node.js console output (npm package colors)

open sourceMITfree

colors.js (the npm package colors) adds colour and style to text in the Node.js console: text colours, bright colours, background colours and styles such as bold and dim, plus effects such as rainbow. By default it extends String.prototype so you can write 'text'.red; require('colors/safe') leaves String alone. npm's latest version is still 1.4.0 from September 2019, and the repository's master branch carries code that loops forever when imported (see limitations). Chalk is an alternative.

Problems it solves

  • print coloured text in a Node.js terminal app
  • style console output with bold and background colours in JavaScript
  • colour log messages in a Node.js CLI

Features

  • text, bright, background and bright background colours
  • styles such as bold, dim, italic and underline
  • rainbow and other text effects
  • a safe mode that doesn't extend String.prototype
  • custom themes

Limitations

  • The repository's master branch (version 1.4.44-liberty-2, January 2022) loops forever printing garbled text when imported, so don't install it from GitHub; npm serves 1.4.0.123
  • By default it extends String.prototype; use colors/safe to avoid that.1
  • npm's latest release, 1.4.0, dates from September 2019.3

Alternatives

The same job

These do what colors.js does.

  1. Chalk Terminal string styling for Node.js: colours, backgrounds and text styles
  2. strip-ansi Strip ANSI escape codes from a string

Compare colors.js with the top 3