Question: How to display the current filename?
console.log(__filename);This gives you local filename of the current module.
Question: How to display the current directory name?
console.log(__dirname);This gives you local dirname of the current module.
Question: How to call a function after 5 seconds?
For this, you can use a global function i.e setTimeout.
function helloFunction(){ console.log( "Hello, World!"); } /* helloFunction will call after 5 seconds*/ setTimeout(helloFunction, 5000);
Question: How to stop calling a function which was started with setTimeout?
For this, you can use a global function i.e clearTimeout.
function helloFunction(){ console.log( "Hello, World!"); } /* helloFunction will call after 5 seconds*/ var funcObj=setTimeout(helloFunction, 5000); //stop funtion clearTimeout(funcObj);
Question: How to call a function in every 7 seconds?
For this, you can use a global function i.e setInterval.
function helloFunction(){ console.log( "Hello, World!"); } /* helloFunction will call in every 7 seconds*/ setInterval(helloFunction, 7000);
Question: How to stop calling a function which was started with setInterval?
For this, you can use a global function i.e clearInterval
clearInterval(funcObj);
Question: What are different Console Methods to print info, error, warning etc?
- console.log: Prints to stdout with newline.
- console.error: Prints to stderr with newline.
- console.dir: Uses util.inspect on obj and prints resulting string to stdout.
- console.time: Mark the time
- console.timeEnd: Mark the time end
- console.trace: Print to stderr Trace
Question: What are Process Events?
The process object is a global object and can be accessed from anywhere.
process.on('exit', function(code) { console.log('About to exit with code:', code); }); console.log("Program Ended");
Question: What are different the Process Events?
- exit
- beforeExit
- uncaughtException
- Signal Events