Promises and callbacks are very basic concepts and every javascript developer should know the difference.

Let's try to understand with a small example:

someWork() is a function that is going to take roughly around 2 seconds and we want to execute otherWork() function once someWork() is done. This can be achieved using a Callback or Promise.

Callback


AWS IoT Core is a highly scalable platform for IoT devices. I automated the creation of Certificates, Things, and Attaching policy using AWS SDK with the below steps.

Step 1:

I created an IAM user with programmatic access and attached the AWSIoTFullAccess policy.


Scalable Cloud Stack for MVP

As Software Architect at Code B, Every month I work on a few MVP(Minimum Viable Product) applications using the MEAN/MERN stack and always want them to be ready for sudden traffic.

Below is the most common stack I use for scalable deployment.

Authentication

The best practice is to not develop this part and use third-party services.

I stick with AWS Cognito or Google Firebase Authentication depending on the client's cloud preferences.

Database

I prefer to go with managed services for databases and MongoDB Atlas is mostly what I use.

Firestore is also a good option if the frontend needs real-time data(Stock Price…


tree-data with ag-grid

demo: https://ag-grid-tree.codeb.online

ag-grid is a feature-rich library and I have used it on many projects. I was working on POC for 1 project and we needed to represent tree data inside the table.

tree-data can be easily achieved using enterprise edition, but since it was just a POC I tried to achieve it using community version with custom code.

Github: https://github.com/riddheshganatra/ag-grid-tree

Let's start with code:

index.html


Let's make service using node js to create ‘QR codes’(CPU intensive task) to understand how can we use C++ for optimizations.

Results for generating 10000 Qr Codes:

C++ single thread:2960.125ms

Nodejs: 19180.051ms

Node js code to generate QR codes:


Many developers have some tough time understanding promises in javascript.

We will try to understand promise in javascript through some basic examples.

  1. Create and use promise:

someTask is a function which returns a promise. When async task is successfully completed, we can call resolve and if there is some error we will use reject.

When we call a function which returns a promise,

  1. ‘.then’ is executed if promise completes successfully(resolved)
  2. ‘.catch’ if promise fails(rejected)

Both tasks here are independent, second task doesn't wait for the first to be resolved.

someTask() can do any async task like HTTP call, DB call…


process used memory

Some time back, I came across a requirement to process a huge excel file in node js.

An obvious choice was to use Transform stream. Development was not as smooth as I was expecting. So I decided to share my experience.

I have taken a small part of the code which will accept excel file from API(Multer Custom Storage-multipart form data), process file using transform stream and pipe processed file to response.

Step 1: In Controller, create excelWriter using xlsx-write-stream package and attach it in the request object. …


I came across a requirement where admin can listen call logs of his employees on website. I had recording names stored in mongoDB.

I narrowed down to 2 choices,

1)Stream audio files using node js api on demand

2)Host all audio files using NGINX and then just send name of audio file in api response.

I thought second approach will be more clean way but I wanted to keep my audio files secure. So I used auth_request module from NGINX for authentication.

Let's start with example

I will be using docker compose.We have 2 docker compose file, docker-compose.yml(base file) and docker-compose.dev.yml file.

1)docker-compose file…

Riddhesh Ganatra

Software Architect, Full Stack Web developer, MEAN/MERN stack, Microservices, etc

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