assert.deepStrictEqual() function in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:24:54

176 Views

The assert module provides a bunch of different functionalities that are used for function assertion. One of them is deepStrictEqual() function. This function is used to test the deep equality between the actual and expected parameters. An assertion error will be raised if the condition is not fulfilled.Syntaxassert.deepStrictEqual(actual, expected[, message])ParametersThe above parameters are described as below −actual – This is the actual value that will be evaluated against the expected parameters.expected – This is the expected parameter value which is matched against the actual value.message – This parameter holds the string message value to be printed if the actual and expected parameters do ... Read More

Logging in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:24:21

299 Views

Logging is a very essential part in any application whether it is made in Node.js or any other programming languages. Logging helps us to detect weird behaviours of an application along with real-time errors and exceptions. One should definitely put logical logs in their application. These logs help the user to identify any mistakes and resolve it on urgent basis.There are 5 different log levels which are present at the moment with the user. These log levels are used to define different kinds of logs and helps the user to identify different scenarios. The log levels must be carefully configured ... Read More

Assert Module in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:23:55

205 Views

The assert module provides a bunch of different functionalities that are used for function assertion. This module provides these functions for verifying invariants in a program. We can use assertion for a null check or different other checks. The assertion does not impact any running implementation. It only checks the condition and throws an error if the error is not satisfied.Installing the Assert Modulenpm install assertThe assert module is an inbuilt Node.js module, so you can skip this step as well.Importing the module in your functionconst assert = require("assert");Example Live Democonst assert = require('assert'); let x = 3; let y = ... Read More

Integrating Express-rate-limit in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:23:20

289 Views

Rate-limiting is becoming important day by day to prevent websites from DOS & DDOS attacks. The rate-limiting prevents the system from any type of fake requests or other brute force attacks. Rate limiting limits the number of times an IP can make requests. The expressrate-limit is the npm package to limit the number of requests from a user.Installing the rate-limit moduleRun the below command to install the express rate-limiting module in your application.npm install --save express-rate-limitExampleCreate a file with name – rateLimit.js and copy the below code snippet. After creating file, use the following command to run this code as ... Read More

Creating custom modules in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:22:48

2K+ Views

The node.js modules are a kind of package that contains certain functions or methods to be used by those who imports them. Some modules are present on the web to be used by developers such as fs, fs-extra, crypto, stream, etc. You can also make a package of your own and use it in your code.Syntaxexports.function_name = function(arg1, arg2, ....argN) {    // Put your function body here... };Example - Custom Node ModuleCreate two file with name – calc.js and index.js and copy the below code snippet.The calc.js is the custom node module which will hold the node functions.The index.js ... Read More

Creating an Agent in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:22:19

780 Views

You can use new Agent() method to create an instance of an agent in Node. The http.request() method uses the globalAgent from the 'http' module to create a custom http.Agent instance.Syntaxnew Agent({options})ParametersThe above function can accept the following Parameters −options – These options will contain the configurable options that could be set on an Agent while creation. Below are the fields/options the Agent can have −keepAlive – This method keeps the sockets around whether there are any outstanding requests or not, but keeps them for any future requests without actually re-establishing the TCP connection. One can use 'close' connection' to close this connection. ... Read More

Changing the npm start-script of Node.js

Mayank Agarwal
Updated on 20-May-2021 11:21:38

9K+ Views

The start-script of a Node.js application consists of all the commands that will be used to perform the specific tasks. When starting or initializing a Node.js project, there are a lot of predefined scripts that will be created for running the application. These scripts can be changed as per the need or demand of the project.Script commands are widely used for making different startup scripts of programs in both Node and React. 'npm start' is used for executing a startup script without typing its execution command.Package.json FileThis is the start-up script that needs to be added in the package.json file. ... Read More

agent.createConnection() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 11:20:24

487 Views

The agent.createConnection() method is an interface provided by the 'http' module. This method produces a socket/stream that can be used for the HTTP requests. One can use custom agents to override this method for greater flexibility. A socket/stream can be returned in two ways – either by returning the socket/stream directly from this function, or by passing this socket/stream to the callback.Syntaxagent.createConnection(options, [callback])ParametersThe above function can accept the following parameters −options – These options will contain the connection details for which stream has to be created.callback – This will receive the created socket connection from the agent.ExampleCreate a file with the name ... Read More

Explain the iterator pattern in .NET

Akshay Khot
Updated on 19-May-2021 12:50:41

246 Views

The iterator pattern is used to loop over the elements in a collection and is implemented using the IEnumerator interface. It defines the basic low-level protocol through which elements in a collection are traversed—or enumerated. This is done in a forward-only manner.Here's the IEnumerator interface in C#.public interface IEnumerator{    bool MoveNext();    object Current { get; }    void Reset(); }MoveNext advances the current element or "cursor" to the next position, returning false if there are no more elements in the collection.Current returns the element at the current position (usually cast from object to a more specific type). MoveNext ... Read More

How to work with XML and JSON in .NET?

Akshay Khot
Updated on 19-May-2021 08:19:11

814 Views

Working with JSONJSON is a data format that has become a popular alternative to XML. It is simple and uncluttered with a syntax similar to a JavaScript object. In fact, the term JSON stands for JavaScript Object Notation. The recent versions of .NET provide built-in support for working with JSON data.The System.Text.Json namespace provides high-performance, low-allocating features to process the JSON data. These features include serializing objects to JSON and deserializing JSON back into objects. It also provides types to create an in-memory document object model (DOM) for accessing any element within the JSON document, providing a structured view of ... Read More

Advertisements