Process

The process object is a global that provides information about, and control over, the current process.
As a global, it is always available to applications without using require().

Signal Events

Signal events will be emitted when the Node.js process receives a signal. Please refer to signal(7) for a listing of standard POSIX signal names such as SIGINT, SIGHUP, etc.

The signal handler will receive the signal’s name (‘SIGINT’, ‘SIGTERM’, etc.) as the first argument.

The name of each event will be the uppercase common name for the signal (e.g. ‘SIGINT’ for SIGINT signals).

For example:

// Begin reading from stdin so the process does not exit.
process.stdin.resume();

process.on('SIGINT', function () {
console.log('Received SIGINT. Press Control-D to exit.');
});

// Using a single function to handle multiple signals
function handle(signal) {
console.log(`Received ${signal}`);
}

process.on('SIGINT', handle);
process.on('SIGTERM', handle);

process.hrtime([time])

Ruff available: v1.6.0
Ruff Lite available: v0.7.0

The process.hrtime() method returns the current high-resolution real time in a [seconds, nanoseconds] tuple Array.
time is an optional parameter that must be the result of a previous process.hrtime() call
(and therefore, a real time in a [seconds, nanoseconds] tuple Array containing a previous time)
to diff with the current time.
These times are relative to an arbitrary time in the past,
and not related to the time of day and therefore not subject to clock drift.
The primary use is for measuring performance between intervals.

Passing in the result of a previous call to process.hrtime() is useful for calculating an amount of time passed between calls:

var time = process.hrtime();
// [ 1800216, 25 ]

setTimeout(function() {
var diff = process.hrtime(time);
// [ 1, 552 ]

console.log('Took', diff[0] * 1e9 + diff[1], 'nanoseconds');
// benchmark took 1000000527 nanoseconds
}, 1000);

Constructing an array by some method other than calling process.hrtime() and passing the result to process.hrtime() will result in undefined behavior.

process.nextTick(callback[, …args])

Ruff available: v1.6.0
Ruff Lite available: v0.6.0

  • callback <Function>
  • ...args <any>

The process.nextTick() method adds the callback to the “next tick queue”.
Once the current turn of the event loop turn runs to completion,
all callbacks currently in the next tick queue will be called.

This is not a simple alias to setTimeout(fn, 0), it’s much more efficient.
It runs before any additional I/O events (including timers) fire in subsequent ticks of the event loop.

console.log('start');
process.nextTick(function() {
console.log('nextTick callback');
});
console.log('scheduled');
// Output:
// start
// scheduled
// nextTick callback