Unix

How to print pretty JSON in terminal

  1. var jsonObj = { hi: 'hello' };
  2. console.log(JSON.stringify(jsonObj, null, 2));

How to run bash commands from NodeJS

use child_process.exec to run bash commands

  1. var exec = require('child_process').exec;
  2. var child;
  3. // executes `pwd`
  4. child = exec("pwd", function (error, stdout, stderr) {
  5. sys.print('stdout: ' + stdout);
  6. sys.print('stderr: ' + stderr);
  7. if (error !== null) {
  8. console.log('exec error: ' + error);
  9. }
  10. });