Node.js Assert Complete Reference Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 6 Likes Like Report 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 NodeJS Assert Description Node.js assert() FunctionIf the value is not the truth, then a AssertionError is thrown with a message property set equal to the value of the message parameter.Node.js assert.deepStrictEqual() FunctionThe assert.deepStrictEqual() function tests for deep equality between the actual and expected parameters.Node.js assert.doesNotThrow() FunctionThe assert.doesNotThrow() function asserts that the function fn does not throw an error.Node.js assert.equal() FunctionThe assert.equal() function tests for equality between the actual and the expected parameters.Node.js assert.fail() FunctionThe assert.fail() function throws an AssertionError with the provided error message or with a default error message.Node.js assert.ifError() FunctionThe assert.ifError() function throws a value if the value is not defined or null.Node.js assert.match() FunctionThe assert.match() function expects the string input to match the regular expression.Node.js assert.notDeepEqual() FunctionThe assert.notDeepEqual() function tests deep strict inequality between the actual and the expected parameters.Node.js assert.notDeepStrictEqual() Function The assert.notDeepStrictEqual() function tests for deep strict inequality.Node.js assert.notEqual() FunctionThe assert.notEqual() function tests strict inequality between the actual and the expected parameters.Node.js assert.ok() FunctionThe assert module provides a set of assertion functions for verifying invariants.Node.js assert.rejects() FunctionThe assert.rejects() function awaits the asyncFn promise Node.js assert.strictEqual() FunctionThe assert.strictEqual() function tests strict equality between the actual and expected parameters. Create Quiz Comment K kartik Follow 6 Improve K kartik Follow 6 Improve Article Tags : Web Technologies Node.js Node.js-Methods NodeJS-assert Explore Introduction & Installation NodeJS Introduction3 min readNode.js Roadmap: A Complete Guide6 min readHow to Install Node.js on Linux6 min readHow to Install Node.js on Windows5 min readHow to Install NodeJS on MacOS6 min readNode.js vs Browser - Top Differences That Every Developer Should Know6 min readNodeJS REPL (READ, EVAL, PRINT, LOOP)4 min readExplain V8 engine in Node.js7 min readNode.js Web Application Architecture3 min readNodeJS Event Loop5 min readNode.js Modules , Buffer & StreamsNodeJS Modules5 min readWhat are Buffers in Node.js ?4 min readNode.js Streams4 min readNode.js Asynchronous ProgrammingAsync Await in Node.js3 min readPromises in NodeJS7 min readHow to Handle Errors in Node.js ?4 min readException Handling in Node.js3 min readNode.js NPMNodeJS NPM6 min readSteps to Create and Publish NPM packages7 min readIntroduction to NPM scripts2 min readNode.js package.json4 min readWhat is package-lock.json ?3 min readNode.js Deployments & CommunicationNode Debugging2 min readHow to Perform Testing in Node.js ?2 min readUnit Testing of Node.js Application5 min readNODE_ENV Variables and How to Use Them ?2 min readDifference Between Development and Production in Node.js3 min readBest Security Practices in Node.js4 min readDeploying Node.js Applications5 min readHow to Build a Microservices Architecture with NodeJS3 min readNode.js with WebAssembly3 min readResources & ToolsNode.js Web Server6 min readNode Exercises, Practice Questions and Solutions4 min readNode.js Projects9 min readNodeJS Interview Questions and Answers15+ min read Like