Skip to content

Latest commit

 

History

History
45 lines (38 loc) · 1.02 KB

part1_basics_04.md

File metadata and controls

45 lines (38 loc) · 1.02 KB

Process

process.env

Accesses environment variables

console.log('\nEnvironment');
console.log(process.env);
console.log('\nPath');
console.log(process.env.path);
console.log(process.env['path']);
  • env is an object which contains properties for each env var, not an array
  • env vars can be accessed using a property or using a hash.

process.argv

Accesses arguments

console.log('\nArguments');
process.argv.forEach(function (val, index, array) {
  console.log(index + ': ' + val);
});
  • argv is an array of arguments
  • first argument is always the process that launched the node script
  • second argument is the node script
  • args are modifiable and can be rewritten

process.stdin

Accesses the standard input stream

process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function(text) {
  if (text === '\n')
		process.stdin.pause();
	else
		console.log('entered:' + text);
})
  • resume: allow keyboard input :-)
  • pause: stop accepting input