1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2025-06-15 14:47:53 +02:00
cheatsheets/nodejs-process.md
2023-03-14 12:52:21 +11:00

773 B

title category layout
process Node.js 2017/sheet

Streams

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

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

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

Directories

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

References