Nodejs Process Cheat Sheet

From WikiOD

Here is the cheatsheat of Nodejs Process and basic guide on how to use Nodejs Process

Streams[edit | edit source]

process.stdout.write('...');
process.stderr.write('...');

function stdin(fn) {
  var data = '';

  process.stdin.setEncoding('utf8');
  process.stdin.on('readable', function() {
    var chunk = process.stdin.read();
    if (chunk !== null) data += chunk;
  });

  process.stdin.on('end', function() {
    fn(null, data);
  });
}

stuff[edit | edit source]

process.argv; //=> ['node', 'file.js', 'one', 'two']
process.env; //=> {TERM: 'screen-256color', SHELL: '/bin/bash', ...}

process.exit();
process.exit(1);

Directories[edit | edit source]

process.cwd(); //=> "/tmp"
process.chdir('dir');

References[edit | edit source]

Credit:rstacruz