Skip to content
Related Articles
Open in App
Not now

Related Articles

NodeJS process.nextTick() Method

Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 30 Aug, 2022
Improve Article
Save Article

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.



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:



// 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


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!