JavaScript

How to prevent npm install for unsupported Node.js versions

How to prevent npm install for unsupported Node.js versions

  • March 17, 2022

npm configurations allow us to do quite a lot of nifty things. One of them is to allow the project to set the Node.js version that needs to be used in order to run the project. This also provides us with the functionality to prevent npm install for unsupported Node.js...

Detecting dark mode preference using JavaScript

Detecting dark mode preference using JavaScript

  • March 2, 2022

As dark themes have become popular across the web and across operating systems, we might want to check the user’s operating system preference when they visit our website. This way, we can initialize our website accordingly after detecting their dark mode preference. We can make use of the prefers-color-scheme media...

JavaScript: Split string and keep the separators

JavaScript: Split string and keep the separators

  • February 1, 2022

String.prototype.split() is a valuable method to split strings based on a delimiter. There often comes a scenario when we want to split a string and keep the separators in the result. The same JavaScript method provides a way to do so. Before we get into that, for people who are...

Printing JavaScript stack traces using console.trace

Printing JavaScript stack traces using console.trace

  • January 26, 2022

The console object in JavaScript has a lot more useful functions than the most frequently used console.log method. Debugging errors and finding execution flow can be a lot easier by making use of the console.trace method. It allows us to print the current stack trace where the method was called....

Overriding nested dependencies in NPM

Overriding nested dependencies in NPM

  • January 18, 2022

Whenever we install a particular package, it is common to come across a problem with a dependency’s dependency. With the release of npm 8.3, an overrides attribute has been added to solve this problem and allow overriding of nested dependencies in NPM. The problem Let us say your project depends...

Flatten Arrays in Vanilla JavaScript with flat() and flatMap()

Flatten Arrays in Vanilla JavaScript with flat() and flatMap()

  • January 5, 2022

ES2019 introduced two methods on the array prototype that would make life so much simpler for developers. These are flat() and flatmap() which help in flattening arrays. Array.prototype.flat() As the name suggests, the flat() method returns a new array with elements of the subarray flattened into it, that is the...

Using GroupBy on an array of objects in JavaScript

Using GroupBy on an array of objects in JavaScript

  • December 29, 2021

Array grouping is a fairly common operation in any project. Until recently, we had to either write our own implementation or use third-party libraries when wanting to GroupBy on an array of objects in JavaScript. That will soon no longer be needed since a native implementation has been introduced in...

Node.js introduces node: protocol imports

Node.js introduces node: protocol imports

  • December 23, 2021

Node.js recently introduced a node: protocol for built-in modules. Built-in node modules can now be imported by prefixing the node: protocol prefix. So, what previously used to be can now be imported as Benefits It is currently supported: