Javascript Tips

A quick tutorial to use Promise.All() and P-Map to improve the performance of multi-loop asynchronous calls in javascript

Photo by Willian Justen de Vasconcellos on Unsplash


The async/await expression is commonly used to handle asynchronous operations in JavaScript since it has many advantages over callback and then() patterns. The await expression is the ideal choice for handling asynchronous functions in the simplest manner. However, this simplicity, if not dealt properly, sometimes can also lead to problems…

The comparison of check, trigger and application code

Recently I am involved with a project where I have to develop a department management tool, to which, I have to apply some constraints.

For instance, some simple rules are

  1. The parent id has to be chosen only from the existing department IDs.
  2. If a department ID has been used…

Microsoft Graph Golang

The best solution to the error of Insufficient privileges to complete the operation while updating password profile via Microsoft Graph API

Recently I was working on a project that integrates its information management system with Microsoft office365 and Azure AD for the mail exchange service. During the development, I met a problem that resetting user passwords in an azure active directory via Microsoft graph API always shows the following error:


A much powerful but uncommon way of mocking service in jest unit test

Photo by Victoria Strukovskaya on Unsplash

Jest has two ways to mock functions: Either by creating a mock function to use in test code or writing a manual mock to override a module dependency. Today I am going to demonstrate how to use manual mock.

Also, this is the continuation of the article

Solution structure:

├── gui

Javascript Programming

A demo of how to implement job queues with Bull/Redis/Node.js/Javascript

Photo by on Unsplash

Queues can solve many different problems in an elegant way, from smoothing out processing peaks to creating robust communication channels between microservices or offloading heavy work from one server to many smaller workers, etc. So how can you achieve this in the JavaScript world?

The answer is Bull. Bull is…

Javascript Programming

How to use Sinon mock in node.js to test a controller which uses the service/APIs via node-fetch

Unit testing is very powerful and essential for project/product development, but how to write it when it comes to calling third-party APIs from the outside is always a pain for devs. Here I’d like to demonstrate how to use Sinon to mock different services/APIs in a unit test with node.js…

Kris Ma

Every failure is leading towards success. A happy risk-taker, multi-times failed entrepreneur, rusted polyglot, programming retiree, world traveler.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store