Process.emitWarning - Node documentation
method Process.emitWarning

Usage in Deno

import { type Process } from "node:process";
Process.emitWarning(
warning: string | Error,
ctor?: Function,
): void

The process.emitWarning() method can be used to emit custom or application specific process warnings. These can be listened for by adding a handler to the 'warning' event.

import { emitWarning } from 'node:process';

// Emit a warning with a code and additional detail.
emitWarning('Something happened!', {
  code: 'MY_WARNING',
  detail: 'This is some additional information',
});
// Emits:
// (node:56338) [MY_WARNING] Warning: Something happened!
// This is some additional information

In this example, an Error object is generated internally byprocess.emitWarning() and passed through to the 'warning' handler.

import process from 'node:process';

process.on('warning', (warning) => {
  console.warn(warning.name);    // 'Warning'
  console.warn(warning.message); // 'Something happened!'
  console.warn(warning.code);    // 'MY_WARNING'
  console.warn(warning.stack);   // Stack trace
  console.warn(warning.detail);  // 'This is some additional information'
});

If warning is passed as an Error object, the options argument is ignored.

Parameters

warning: string | Error

The warning to emit.

optional
ctor: Function

Return Type

void
Process.emitWarning(
warning: string | Error,
type?: string,
ctor?: Function,
): void

Parameters

warning: string | Error
optional
type: string
optional
ctor: Function

Return Type

void
Process.emitWarning(
warning: string | Error,
type?: string,
code?: string,
ctor?: Function,
): void

Parameters

warning: string | Error
optional
type: string
optional
code: string
optional
ctor: Function

Return Type

void
Process.emitWarning(
warning: string | Error,
): void

Parameters

warning: string | Error
optional
options: EmitWarningOptions

Return Type

void