Created
February 14, 2015 13:58
-
-
Save kshirish/af50f7656d704505d809 to your computer and use it in GitHub Desktop.
node api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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