Open In App

NodeJS process.nextTick() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

The process object is one of the few global objects provided by the NodeJS core API. It can be accessed from anywhere, thus its methods can also be accessed. Such is a method called process.nextTick() which is used by developers in real-time applications every day to defer the execution of a function until the next Event Loop Iteration.

Syntax:

process.nextTick()

Return Value:

In the code of snippet, the second console is printed first because this is a part of the current iteration of the event loop, and the first console is a part of a callback function that is associated with the process.nextTick() executed in the next iteration of the event loop.

Below examples illustrate the use of the process.nextTick() property in NodeJS:

Example:

Javascript




// Node.js program to demonstrate the
// process.nextTick() Property
    
// Include process module
const process = require('process');
 
process.nextTick(() => {
  console.log('Executed in the next iteration');
});
 
console.log('Executed in the current iteration');


Command to run:

node filename

Output:


Last Updated : 30 Aug, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads