Skip to content

Instantly share code, notes, and snippets.

@tizzo
Created November 12, 2014 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tizzo/1bbf8b176cbe438b17d8 to your computer and use it in GitHub Desktop.
Save tizzo/1bbf8b176cbe438b17d8 to your computer and use it in GitHub Desktop.
Node.js Enable/disable colors based on process.itTTY
#! /usr/bin/env node
var prettyjson = require('prettyjson');
var someDataStructure = {
firstLevelA: {
secondLevel1: {
thirdLevelA: 'foo',
thirdLevelB: []
}
},
firstLevelB: {},
firstLevelC: {}
};
console.log(prettyjson.render(someDataStructure, {noColor: !process.stdout.isTTY}));
{
"name": "pty-example",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"prettyjson": "^1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment