Skip to content

Instantly share code, notes, and snippets.

@kshirish
Created February 14, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kshirish/af50f7656d704505d809 to your computer and use it in GitHub Desktop.
Save kshirish/af50f7656d704505d809 to your computer and use it in GitHub Desktop.
node api
// global object
console.log(process);
process.on('uncaughtException', function(err) {
console.log('Caught exception: ' + err);
});
setTimeout(function() {
console.log('This will still run.');
}, 500);
// Intentionally cause an exception, but don't catch it.
nonexistentFunc();
// kill itself
process.kill();
process.on('exit', function(){
console.log('time to exit');
});
// listen evertime for data
process.stdin.on('data', function(chunk){
console.log(chunk.toString());
});
// another way for echo terminal
process.stdin.on('data', function(chunk){
process.stdout.write(chunk.toString());
});
// for once if only readable
process.stdin.on('readable', function() {
console.log('yes it is readable.');
});
// current location
process.cwd();
// step back
process.chdir('..');
// EMIT exit and abort respectively
process.exit();
process.abort();
//try-catch block
try {
process.stdout.destroy();
} catch(e) {
console.log('**************');
console.log(e);
console.log('**************');
}
// kill a pid
process.kill(22615)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment