Node.js Assert Complete Reference
Last Updated :
23 Jul, 2025
Assert module in Node.js provides a bunch of facilities that are useful for the assertion of the function. The assert module provides a set of assertion functions for verifying invariants. If the condition is true it will output nothing else an assertion error is given by the console.
Example:
JavaScript
// Requiring the module
const assert = require('assert').strict;
var a = "GeeksforGeeks";
var b = "Geeks4Geek";
// Function call
try {
assert.strictEqual(a, b);
} catch(error) {
console.log("Error: ", error)
}
Output:
Error: AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: + actual â expected + âGeeksforGeeksâ â âGeeks4Geekâ ^ at Object. (C:\Users\Lenovo\Downloads\index.js:4:12) at Module._compile (internal/modules/cjs/loader.js:1138:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10) at Module.load (internal/modules/cjs/loader.js:986:32) at Function.Module._load (internal/modules/cjs/loader.js:879:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) at internal/main/run_main_module.js:17:47 { generatedMessage: true, code: âERR_ASSERTIONâ, actual: âGeeksforGeeksâ, expected: âGeeks4Geekâ, operator: âstrictEqualâ }
The Complete List of NodeJS Assert are listed below:an