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. Comment K kartik Follow 6 Improve K kartik Follow 6 Improve Article Tags : Web Technologies Node.js Node.js-Methods NodeJS-assert Explore Node.js Tutorial 3 min read Introduction & Installation NodeJS Introduction 3 min read Node.js Roadmap: A Complete Guide 6 min read How to Install Node.js on Linux 6 min read How to Install Node.js on Windows 5 min read How to Install NodeJS on MacOS 6 min read Node.js vs Browser - Top Differences That Every Developer Should Know 6 min read NodeJS REPL (READ, EVAL, PRINT, LOOP) 4 min read Explain V8 engine in Node.js 7 min read Node.js Web Application Architecture 3 min read NodeJS Event Loop 5 min read Node.js Modules , Buffer & StreamsNodeJS Modules 5 min read What are Buffers in Node.js ? 4 min read Node.js Streams 4 min read Node.js Asynchronous ProgrammingAsync Await in Node.js 3 min read Promises in NodeJS 7 min read How to Handle Errors in Node.js ? 4 min read Exception Handling in Node.js 3 min read Node.js NPMNodeJS NPM 6 min read Steps to Create and Publish NPM packages 7 min read Introduction to NPM scripts 2 min read Node.js package.json 4 min read What is package-lock.json ? 3 min read Node.js Deployments & CommunicationNode Debugging 2 min read How to Perform Testing in Node.js ? 2 min read Unit Testing of Node.js Application 5 min read NODE_ENV Variables and How to Use Them ? 2 min read Difference Between Development and Production in Node.js 3 min read Best Security Practices in Node.js 4 min read Deploying Node.js Applications 5 min read How to Build a Microservices Architecture with NodeJS 3 min read Node.js with WebAssembly 3 min read Resources & ToolsNode.js Web Server 6 min read Node Exercises, Practice Questions and Solutions 4 min read Node.js Projects 9 min read NodeJS Interview Questions and Answers 15+ min read Like