Node.js には、標準で assert モジュールが用意されています。
import assert from 'node:assert';
const count = 0;
assert(count > 0, 'count should be positive');console オブジェクトには assert() メソッドが用意されており、こちらは何もモジュールをインポートしなくても使用できます。
console.assert(count > 0, 'count should be positive');