Skip to content

Instantly share code, notes, and snippets.

@o-az
Last active October 6, 2023 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save o-az/fbac55d446603fee118b00c14cd35ef7 to your computer and use it in GitHub Desktop.
Save o-az/fbac55d446603fee118b00c14cd35ef7 to your computer and use it in GitHub Desktop.
Suppress all Node.js warnings (including deprecation warnings)
const { emit: originalEmit } = process;
/**
* @param {string} event
* @param {{ name: string; }} error
*/
function suppresser(event, error) {
return event === "warning" && error.name === "ExperimentalWarning"
? false
: originalEmit.apply(process, arguments);
}
process.emit = suppresser;
@o-az
Copy link
Author

o-az commented Oct 6, 2023

How to use:

node --require="suppress-warnings.cjs" index.js

or with ts-node/tsx:

node --loader"ts-node/esm" --require"suppress-warnings.cjs" index.ts

or set in NODE_OPTIONS environment variable:

NODE_OPTIONS="--require=suppress-warnings.cjs" node index.js

Also works with npm/pnpm/yarn:

NODE_OPTIONS="--require=suppress-warnings.cjs" pnpm run my-awesome-script

or, if you're on Node.js v19 or higher, rename to suppress-warnings.mjs and replace --require with --import in the command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment