Assertions
assert.ok()
Checks truthiness, not equality to true. Use assertions for programmer invariants or tests, not as the only validation of untrusted requests. Tested on Node.js 22.16.0. Example output (one line per entry): ["ERR_ASSERTION"].
Formal Syntax & Structure
nodejs syntaxnodejs
assert.ok(value[, message])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| value | any | Value to check. |
| message | string | Error | Failure detail. |
Return Value
undefined
Returns normally or throws.
Working Example
Example Snippetnodejs
import assert from 'node:assert/strict';assert.ok(1);try { assert.ok(0);}catch (e) { console.log(e.code);}