Skip to content

Instantly share code, notes, and snippets.

@xgqfrms-GitHub
Created June 13, 2017 09:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgqfrms-GitHub/92aa2b00249f15084d24aa2e0a5d0300 to your computer and use it in GitHub Desktop.
Save xgqfrms-GitHub/92aa2b00249f15084d24aa2e0a5d0300 to your computer and use it in GitHub Desktop.
format output json object in node.js

node.js format output json object

https://stackoverflow.com/a/10729284/5934465

https://stackoverflow.com/questions/10729276/how-can-i-get-the-full-object-in-node-jss-console-log-rather-than-object

    
console.log(JSON.stringify(process.config, null, 4));

console.log(`\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n`);


    
#!/usr/bin/env node

const colors = require('colors');

/*

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/toString


https://nodejs.org/api/buffer.html

https://stackoverflow.com/questions/16965281/node-js-tostring-encoding

https://stackoverflow.com/questions/34476754/what-encodings-does-buffer-tostring-support/34476785



https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify



JSON.stringify() 方法将一个JavaScript值转换为一个JSON字符串,如果指定了一个replacer函数,则可以替换值,或者如果指定了一个replacer数组,可选地仅包括指定的属性。

语法
JSON.stringify(value[, replacer [, space]])



# how to stringify object in node.js

https://www.npmjs.com/package/stringify-object

https://www.npmjs.com/package/node-stringify


http://timelessrepo.com/json-isnt-a-javascript-subset

https://stackoverflow.com/questions/16005091/node-js-javascript-stringify


https://stackoverflow.com/questions/5612787/converting-an-object-to-a-string


https://stackoverflow.com/questions/10729276/how-can-i-get-the-full-object-in-node-jss-console-log-rather-than-object








*/


console.log(`\n\n\n******************************\n\n\n`);

console.log(`\nprocess = \n`.red, typeof(process));
// object & JSON.stringify() 


// let xxx = JSON.stringify(process);


console.log(`\nprocess = \n`.rainbow, process);


console.log(`\n\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n\n\n`);



console.log(`\nprocess.argv = \n`.rainbow, typeof(process.argv));
// object & JSON.stringify() 


console.log(`\nprocess.argv = \n`, process.argv);


console.log(`\n\n\n++++++++++++++++++++++++++++++++++++++\n\n\n`);



console.log(`\nprocess.env = \n`.white, typeof(process.env));
// object & JSON.stringify() 


console.log(`\nprocess.env = \n`, process.env);

console.log(`\n\n\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n\n`);



console.log(`\nprocess.config = \n`, process.config);


console.log(`\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n`);

console.log(JSON.stringify(process.config, null, 4));

// https://stackoverflow.com/a/10729284/5934465


console.log(`\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n`);

console.log(`\nprocess.argv = \n`.rainbow, typeof(process.argv));
// array object & JSON.stringify() 


console.log(`\nprocess.argv = \n`, process.argv);

console.log(JSON.stringify(process.argv, null, 4));

new

#!/usr/bin/env node

const colors = require('colors');

/*

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/toString


https://nodejs.org/api/buffer.html

https://stackoverflow.com/questions/16965281/node-js-tostring-encoding

https://stackoverflow.com/questions/34476754/what-encodings-does-buffer-tostring-support/34476785



https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify



JSON.stringify() 方法将一个JavaScript值转换为一个JSON字符串,如果指定了一个replacer函数,则可以替换值,或者如果指定了一个replacer数组,可选地仅包括指定的属性。

语法
JSON.stringify(value[, replacer [, space]])



# how to stringify object in node.js

https://www.npmjs.com/package/stringify-object

https://www.npmjs.com/package/node-stringify


http://timelessrepo.com/json-isnt-a-javascript-subset

https://stackoverflow.com/questions/16005091/node-js-javascript-stringify


https://stackoverflow.com/questions/5612787/converting-an-object-to-a-string


https://stackoverflow.com/questions/10729276/how-can-i-get-the-full-object-in-node-jss-console-log-rather-than-object








*/


console.log(`\n\n\n******************************\n\n\n`);

console.log(`\nprocess = \n`.red, typeof(process));
// object & JSON.stringify() 


// let xxx = JSON.stringify(process);


console.log(`\nprocess = \n`.rainbow, process);


console.log(`\n\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n\n\n`);



console.log(`\nprocess.argv = \n`.rainbow, typeof(process.argv));
// object & JSON.stringify() 


console.log(`\nprocess.argv = \n`, process.argv);


console.log(`\n\n\n++++++++++++++++++++++++++++++++++++++\n\n\n`);



console.log(`\nprocess.env = \n`.white, typeof(process.env));
// object & JSON.stringify() 


console.log(`\nprocess.env = \n`, process.env);

console.log(`\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n`);

console.log(`\nprocess.env = \n`, JSON.stringify(process.env, null, 4));
// object object ???

console.log(`\n\n\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n\n`);



console.log(`\nprocess.config = \n`, process.config);


console.log(`\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n`);

console.log(`\nprocess.config = \n`, JSON.stringify(process.config, null, 4));

// https://stackoverflow.com/a/10729284/5934465
// array object ???


console.log(`\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n`);

console.log(`\nprocess.argv = \n`.rainbow, typeof(process.argv));
// array object & JSON.stringify() 


console.log(`\nprocess.argv = \n`, process.argv);

console.log(JSON.stringify(process.argv, null, 4));

@xgqfrms-GitHub
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment