Top 5 Node.js Design Patterns for Scalable Application

Node.js is a powerhouse for building scalable applications, but writing efficient and maintainable code requires more than just asynchronous magic. To truly level up, you need design patterns — proven solutions to common software architecture challenges. Whether you’re working on a microservices system, an API backend, or a real-time application, using the right design patterns will make… Continue reading Top 5 Node.js Design Patterns for Scalable Application

Promise.all(), Promise.any(), and More: Handling Multiple Promises in JavaScript

Promise Let’s have an overview of Promise first. In JavaScript, Promise is used to perform asynchronous operations. It’s an object that contains a status & represents the eventual completion (or failure) of an asynchronous operation and its resulting value. For example, uploading an image to the server is an asynchronous operation. When the image upload process is done, it can return… Continue reading Promise.all(), Promise.any(), and More: Handling Multiple Promises in JavaScript

Promise.allSettled()

The Promise.allSettled() static method takes an iterable of promises as input and returns a single Promise. This returned promise fulfills when all of the input’s promises settle (including when an empty iterable is passed), with an array of objects that describe the outcome of each promise. Promise.allSettled() is typically used when you have multiple asynchronous… Continue reading Promise.allSettled()

Filter duplicate emails from array

let noteRecepinets = [recepientEmail, recepient2, employee1, employee2, salesAssociateEmail];                                 let validnoteRecepinets = […new Set(noteRecepinets.filter(el => checkForParameter(el)))]; /**          * Function to check the validity of a parameter.          * @param {string|number} parameter    … Continue reading Filter duplicate emails from array

Capitalizing Strings in JavaScript

/**  * @description Capitalizes the first letter of a given string  * @param {string} str – The string to capitalize  * @returns {string|boolean} – Capitalized string or false if invalid  */ function capitalizeFirstLetter(str) {     if (typeof str !== “string” || str.length === 0) return false;          return str.charAt(0).toUpperCase() + str.slice(1);… Continue reading Capitalizing Strings in JavaScript

Rounding Numbers in JavaScript

/**  * @description Rounds a number to the specified decimal places  * @param {number} num – The number to round  * @param {number} decimals – Number of decimal places  * @returns {number|boolean} – Rounded number or false if invalid  */ function roundToDecimals(num, decimals) {     if (typeof num !== “number” || typeof decimals !==… Continue reading Rounding Numbers in JavaScript

Checking if an Input is a Date Object

/**  * @description Check whether the given value is a Date object  * @param {any} dateObj – The value to check  * @returns {boolean} – True if it’s a valid Date object, otherwise false  */ function isInstanceOfDate(dateObj) {     return dateObj instanceof Date && !isNaN(dateObj); } console.log(isInstanceOfDate(new Date())); // true console.log(isInstanceOfDate(“2024-02-28”)); // false (string,… Continue reading Checking if an Input is a Date Object

JavaScript code to Add/Subtract days from Date Object

let prevPremVal = null; // Initialize previous premium value customrecord_jj_new_commi_report_ahap29SearchObj.run().each(function(result) {     let isPremium = result.getValue(result.columns[36]); // Check if it’s premium     let tieredPremium = getTieredPremiumValue(result.getValue(result.columns[38]), result.getValue(result.columns[61]));     log.debug(“Is Premium:”, isPremium);     log.debug(“Tiered Premium:”, tieredPremium);     // If isPremium is true and tieredPremium is valid, use tieredPremium     //… Continue reading JavaScript code to Add/Subtract days from Date Object