// suppress-node-warnings.cjs
// inspired by
// https://github.com/nodejs/node/issues/30810#issuecomment-1383184769
const { emit: originalEmit } = process;
function suppresser(event, error) {
return event === 'warning' && error.name === 'ExperimentalWarning'
? false
: originalEmit.apply(process, arguments);
}
process.emit = suppresser;
node --require ./suppress-node-warnings.cjs <whatever>
I'm using "type": "module"
in package.json
so I needed to use .cjs
.
I'm also using ts-node
so to run TypeScript files, I have the following script:
"scripts": {
"run-ts": "node --loader ts-node/esm --require ./scripts/suppress-node-warnings.cjs"
}
now I can run ts file with npm run-ts filename.ts
.
You can also use NODE_NO_WARNINGS=1
to suppress all warnings. E.g.,
NODE_NO_WARNINGS=1 node <...>