• Stars
    star
    5,152
  • Rank 8,058 (Top 0.2 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 14 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

get colors in your node.js console

colors.js

Build Status version dependencies devDependencies

Please check out the roadmap for upcoming features and releases. Please open Issues to provide feedback, and check the develop branch for the latest bleeding-edge updates.

get color and style in your node.js console

Demo

Installation

npm install colors

colors and styles!

text colors

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • gray
  • grey

bright text colors

  • brightRed
  • brightGreen
  • brightYellow
  • brightBlue
  • brightMagenta
  • brightCyan
  • brightWhite

background colors

  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite
  • bgGray
  • bgGrey

bright background colors

  • bgBrightRed
  • bgBrightGreen
  • bgBrightYellow
  • bgBrightBlue
  • bgBrightMagenta
  • bgBrightCyan
  • bgBrightWhite

styles

  • reset
  • bold
  • dim
  • italic
  • underline
  • inverse
  • hidden
  • strikethrough

extras

  • rainbow
  • zebra
  • america
  • trap
  • random

Usage

By popular demand, colors now ships with two types of usages!

The super nifty way

var colors = require('colors');

console.log('hello'.green); // outputs green text
console.log('i like cake and pies'.underline.red); // outputs red underlined text
console.log('inverse the color'.inverse); // inverses the color
console.log('OMG Rainbows!'.rainbow); // rainbow
console.log('Run the trap'.trap); // Drops the bass

or a slightly less nifty way which doesn't extend String.prototype

var colors = require('colors/safe');

console.log(colors.green('hello')); // outputs green text
console.log(colors.red.underline('i like cake and pies')); // outputs red underlined text
console.log(colors.inverse('inverse the color')); // inverses the color
console.log(colors.rainbow('OMG Rainbows!')); // rainbow
console.log(colors.trap('Run the trap')); // Drops the bass

I prefer the first way. Some people seem to be afraid of extending String.prototype and prefer the second way.

If you are writing good code you will never have an issue with the first approach. If you really don't want to touch String.prototype, the second usage will not touch String native object.

Enabling/Disabling Colors

The package will auto-detect whether your terminal can use colors and enable/disable accordingly. When colors are disabled, the color functions do nothing. You can override this with a command-line flag:

node myapp.js --no-color
node myapp.js --color=false

node myapp.js --color
node myapp.js --color=true
node myapp.js --color=always

FORCE_COLOR=1 node myapp.js

Or in code:

var colors = require('colors');
colors.enable();
colors.disable();

Console.log string substitution

var name = 'Marak';
console.log(colors.green('Hello %s'), name);
// outputs -> 'Hello Marak'

Custom themes

Using standard API

var colors = require('colors');

colors.setTheme({
  silly: 'rainbow',
  input: 'grey',
  verbose: 'cyan',
  prompt: 'grey',
  info: 'green',
  data: 'grey',
  help: 'cyan',
  warn: 'yellow',
  debug: 'blue',
  error: 'red'
});

// outputs red text
console.log("this is an error".error);

// outputs yellow text
console.log("this is a warning".warn);

Using string safe API

var colors = require('colors/safe');

// set single property
var error = colors.red;
error('this is red');

// set theme
colors.setTheme({
  silly: 'rainbow',
  input: 'grey',
  verbose: 'cyan',
  prompt: 'grey',
  info: 'green',
  data: 'grey',
  help: 'cyan',
  warn: 'yellow',
  debug: 'blue',
  error: 'red'
});

// outputs red text
console.log(colors.error("this is an error"));

// outputs yellow text
console.log(colors.warn("this is a warning"));

Combining Colors

var colors = require('colors');

colors.setTheme({
  custom: ['red', 'underline']
});

console.log('test'.custom);

Protip: There is a secret undocumented style in colors. If you find the style you can summon him.

More Repositories

1

faker.js

What really happened with Aaron Swartz?
1,522
star
2

say.js

TTS (text to speech) for node.js. send text from node.js to your speakers.
JavaScript
1,476
star
3

pdf.js

Project Deprecated
JavaScript
399
star
4

node_mailer

## Project deprecated, see README
JavaScript
388
star
5

translate.js

translate text from one language to another on node.js and the browser. 30+ languages supported, simple as cake.
JavaScript
309
star
6

asciimo

asciimo - create awesome ascii art with javascript! works in the browser or node.js
JavaScript
281
star
7

webservice.js

## Project deprecated, Use flatiron/restful instead
JavaScript
253
star
8

JSONloops

JSONloops is a real-time, multiuser audio sequencer for node.js and the browser.
JavaScript
184
star
9

bpipe

Browser <==> Unix Pipes
JavaScript
159
star
10

play.js

play sound files from node.js to your speakers, simple as cake and kid approved!
JavaScript
159
star
11

buddypond

Cloud OS and Instant Messenger
JavaScript
148
star
12

natman

Forwards external public ports to internal ports without router access.
JavaScript
138
star
13

cron-editor

Visual Cron Editor - Edit and Create Cron Jobs With Ease
JavaScript
138
star
14

HTML

HTML is The BEST JavaScript templating language EVER
JavaScript
99
star
15

session.js

super simple session middleware for node.js, even has optional "magic" sessions which monkey patch the httpServer with one line!
JavaScript
95
star
16

JSLINQ

Clean and simple port of Microsoft's LINQ to node.js (and the browser)
JavaScript
92
star
17

zztmmo

a zzt based massive multiplayer online game built in node.js and jQuery
JavaScript
68
star
18

The-Git-Rap

WORLD PREMIER EXCLUSIVE GIT RAP BROUGHT TO YOU BY GITHUB
64
star
19

node_hash

a super simple hashing library for node.js
JavaScript
58
star
20

roles.js

a super simple node.js JSON based roles management system
JavaScript
58
star
21

zalgo.js

ĭ̱͓̝̭̱͓̃̅͊ͬͫ̏̅ ̣͙̥̥̺͎̱̻̗̘͖́͆̎ͭ͛̊̔̽̂ͭ̽͊ͅa͎̬̣̺͉̼̬̭͚̝͖͕͇̠̥̬͍̥̪̬̪͓͇̬͓̲̹͈̼͚̥̜̙̩̠̤̖̖̫͔̭͍̘̰̳̥͖͚̱͙̻ͯ̓͗̈̌̿̾̈̐̓͗͑̃̔̿̄̚m͙͍͔̙̪͓̩͚̣͙̘̟̞͙͍̺͕̜̻̯͇͉͇̠̙̬͉̖̞̫͇͍̹̖̝̣ͫ͑̈ͥ̀̑͊͆̿ ̬̰̮͉̭̬͙̫̙͖̪̮͎͎͕͉̠̜̦͍̹̦̥̳̙̬̺̲͙͈̹̹̠̘͔̙ͨ̇͊̉͂͆ͬͯ̄̃ͪͅz͓͇̱̝̭̜̫̞͚͉̭̫̞͇̮̟̫̗̼̟͐ͦ͗̈̀͌͒̽̆ͧͭ̈͂̾̇̃̂ͅa̹̜̭͔͇̬͍̟̤͈̙̯͍͕͈͇̱̞͖̼̥̺͉̍̑̒̎l͙̙̼̰̩̟̗̙̝̜̙̺̖͍̜̞̤̞͔͖̞̘̣͍̖̰̙͔̖̳̼͐̓̾̇̑ͤ͆̈̎̔̇̃̐͒g͔̦͖̞̯͙̠̭̫̜͈̺̮̠̜̻̱̥̙ͦͧ̉͆̊̎̐ͅo͍̥̹̮͔̣̮̜̱̫̼͚̘̮̝̰̣̼͕͉͕͖̼̫͓̠̣͖̼̦͍͍̟̗̤̖̤̞̞͇̠̟̥̻͎̩̠̭̲̞͇͙̦̣̬͉̱̳͙̫̫͈̻̊̓ͫ̈ͅͅ,̼̦͓̤̘̦͖͈̜̭̩̯̹͈̭̜̙̞̿͊ͩ̄̐ͨ͐̈̎̒̉̆̍ͪ̀̿̍̌̚ ̞̳͉̮̯̱͉̜̰̜͔͈͓̹̻̭͔̖̟͓̭̜͎̰̹̪̭̖͇̟̗͕̠̞̳̤̯͕̠̳̙̘͛ͫ̅̓̿ͥ̓d͎͖̲̝̲̩̹̲̬̪̖̦̯͖̩̤̫͎̠̖͚̘̋͂̉̑̍͒̎ͅe̟͔͍̺͔̖͕̺̰̯͎̞̥̠͙̮͚̪̝͇̱̺̗̻̫̝͚͍͉̪͚̫͚͓͓̩̘͖͎̣̞̹͍ͯ̋̾ͪͮ́s̬͎͍̻͍̹̘̣͕̰͍͔̱̯̜̰̹̥̐̇̆͊ͯ̈ͮ̇̍̎̆ͥ̆̌̍̋̈̽̍ͅt͖̩̺̫̘̰̬̝̙̰̱̦̹͓̦͍̩͖̤̩͉̭̳̲̬̘̮̥̠̤̺͇͈̩̺̞̗̰̘͚̯̦̺̤̥̞̞̻̯̳͙͕̹̜̩͔̫̺̖͍̺́͋ͫ̿ͨ̿ͩ̀͊͌͐͛̂̊̄ͅͅr͎̺͕̟̦̩̙̯͓͈̪̜̤͎͔̯͕̫͉͇͓͔̘̪̝̤̩̣̺̮͉̘̠̠̣̟̮͚̠̘̹͓̥͉͖͓̞͍͖̼̯̤̦̟͔̦̖͔͙̝̫͓͉̖̳̞̅͐ͩ̔̄ͯ͌́̋̒ͧ̽͆̀o̮̳̞̭̪̣͙̰̭̱̺̬̻͙̰̰̣̪̩̱̫̱̞̣͇̭̫̺̙̹͓̭͕̮͕̞̦̗̾͒̉̍̌ͯý͖̖̗̲̥͉̹͚̝̫̟͕̭͖͉͍͇͎͓̣̭̗̤̩͖̼̪͙̣̖̣͓̮̯̤̙͇͖̠̮̦̭̙̝͖̦̞̠̩̺̼̱̱̦̤̥̮̲̻̬̱̋ͪ̓́̒͆̓ͥ͋̓̉̎ͣ̇̍̚ͅe̬͙̱̬͕͚̞̯͎̻̟̙̪̙̝̥̣̫̲̮̖̪ͬͣͭ̉̾ͪ̐ͫ͒̈ͅr̭͓̥̯̘̗̮͍͓̰̦̬͈̖̖̟̹̥̼͙͔̭̪̩͉̠̠̬̜̺̞̘̳̭͔̥̗̱̠͕̠͉̳̻̫̖̘̬̺͍̠͔͙̻̮͉̩̲͈̳̞̊͑͒̿̃̊̉͌̂ͧ̃ͨͬ̅̿ͅͅͅͅͅ ̬̺͚̤͎͓̦̻̻̠͙͎̬̣͖̹͕̫̭̝̗̞͖̣̥̯͉͚̮̗̩̭͛ͭͭ̽ͥ͐͐͆͌ͅo̹̦͈̭̰̬̲̣͓̩͓̖̟͓̼͓̬̾́ͪͬ́ͯ̉̃̒ͫ̌̔ͣ̊ͤ̀ͅf͙̱͚͙̰̳̞̹̠̭̲̮̰͍̼̦̯̳̮͚̝͍̙̻͒ͥ́̐̄͑ͣ ̞̹̮̹̹̲̻̝ͫͫ̓̒̚ẉ̹̘̲̗̟̯͖̲͈͕̮͍̯̟͚̩͖͚̖̭̗͛̔̏̇͆̈̃ͤ̎̎͊ͅe̮͈͔̱͇̩̗͖͕͙̯͎̮̬͈̤͕̣̺̼̰͉̗̙̹̦̤̋̐͐͊̔͋̇b̳̝̱͖̥̘͙͈̻̯̰͕̪̜̻͓̩̙̻̭̗̝̲̘̼̰̘̗̳̪͓̠̗͈͕̰͚̣̱̖̼̺̬̯̻̞͙͈̜̖̪͓̣͎̮͑ͤ̈ͯͩͧͯ̍̍ͯ̉͗̎̎͌̿̌͌s̲͉̦̠̣̺̬͇͙̥̪̖̼͉͉ͣ̃̌͋̀ͮ͗̊̉͂͑̿̑͂̄i̱̪̣̪̭̖̙͔̥͚̳͙̻̪̺̲̞͖̻̠͓̻̹̖͔͔̲̣̤̘̪̩̬͇͉͎̰͕̫̭͓̿͐́̈ͦ̊ͮ̉͌ͨ̏ͨͩ̿̆t͖͙͉͎͓̩̻͖͍͚͓͇̞̲̤͚̳͓̪̟̙̗͕͔̦̫̗͍͔̦͇̪͕͉͙̦̬̐͌͊ͮͅe̝̫̤̠͎͇̟̟͔͓̻̤̼͚̥̤̗̘̰͚̘̪͉̻̥͓̟̘̘̹̼̲̲͚̝̯̱͍͍̜͈̪͕̟̝͕͖̝͕̰̣͙̺͎̜͇̜͕͇̗̘ͥͮͥ̌̉̾ͯ͗ͅͅͅͅs͔̯̗̩͔̪̼̲̫̼͙̼̰̟̥͙̠͕̳̣̯͔̮̥̝̠̤̝͍̤͉͚̖̯͖̰̱̹̜̞͈̭̞͖̓͊́̾̍̑͐ͩͅͅ
JavaScript
55
star
22

javascript-fu

a javascript martial arts library for node.js and the browser. destroy the bad parts with ninja-like precision
JavaScript
50
star
23

ANSIdom

a DOM implementation in ANSI escape codes, render HTML to your terminal
JavaScript
37
star
24

node-raps

a community based rap project to teach and promote node.js
36
star
25

xp

agile programming tools in Coffeescript
CoffeeScript
32
star
26

ohh

share content, have fun, make friends
JavaScript
29
star
27

wizard

experimental configuration wizard that transforms json and json-schemas into user-experiences
JavaScript
25
star
28

ayyo-wars

An open and hackable 2D space battle game
JavaScript
24
star
29

hellonode

( used for testing ) a sample node.js application with a well-formed package.json that has contains required fields for nodejitsu deployment
JavaScript
19
star
30

node-kiwf

kill it with fire, in-process node.js process kill-switch, forces node processes to crash based on certain restrictions like memory usage or uptime
JavaScript
18
star
31

machine.js

turn css selectors into state machines
JavaScript
17
star
32

station

a real-time web i/o reporting application built with hook.io
JavaScript
17
star
33

css_to_json

converts .css files into nested json structures ( json-stylesheets )
JavaScript
16
star
34

the-monolith-versus-the-microservice

a tale of two applications. one built as a monolith. the same built with microservices
JavaScript
15
star
35

vinyl-http

push and receive streams of vinyl over http
JavaScript
11
star
36

prototype-hooks

add before and after hooks to any JavaScript prototype chain
JavaScript
10
star
37

mybuddy

JavaScript
10
star
38

data-behaviors

open-source uber unobtrusive behavior (widget) library built with jQuery. uses HTML5's data-attributes, but still works in IE6
JavaScript
10
star
39

node-backbone-request

A syncing engine for server-side backbone.js built on the request library
JavaScript
10
star
40

node-stats

various tools for crunching node.js community data. mostly incomplete.
JavaScript
7
star
41

vinyl-diff

Perform diffs of vinyl file streams
JavaScript
5
star
42

tracker.js

JavaScript
5
star
43

analog-tv-simulation

simulated analog tv presentation for speakeasy js oct 16 2020
JavaScript
5
star
44

Internet_Money

5
star
45

ePlaying-cards

Software and hardware project for e-paper based playing card deck.
Python
4
star
46

senpai

a digital protege for maintaining your open source empire
JavaScript
4
star
47

microtail

HTTP microservice for easily and safely mapping Unix `tail` commands on your server to authenticated public URLs.
JavaScript
3
star
48

badproject

( used for testing ) an example of a malformed node.js package.json
JavaScript
3
star
49

resourceful-coder

Converts Resourceful resources back into the JavaScript code which created them. Not something you probably need.
JavaScript
3
star
50

command-line-signups

JavaScript
3
star
51

resource-builder

UNRELEASED - simple UI for building Resourceful resources
JavaScript
3
star
52

SupremeJSONCompressor

The Supreme JSON Compressor™ is the world's best JSON Compressor / Decompressor.
JavaScript
3
star
53

buddypond-assets

2
star
54

marak.github.io

JavaScript
2
star
55

badjitsu

( used for testing ) an example of a node.js package.json which is missing required fields for nodejitsu deployment.
JavaScript
2
star
56

marak.com-legacy

website for marak.com
JavaScript
2
star