Understanding Microservices, Web services, APIs and Endpoints
architecture , Uncategorized / December 4, 2019

Many beginners who start development, especially back end, get confused with terms like APIs, Microservices, Web services, endpoints, etc. The aim of this article is to describe what these terms are with a simple example. Please note that the example given here is just a demo. Microservices Microservice Architecture is a way of designing the structure of an application. Microservices are independently deployable services that together make the application. The architecture of an application can be in such a way that it can have multiple independent microservices that can function together. Splitting the application into microservices makes the maintenance of the application easier. It is also helpful in reducing the complexity of the application. Proper microservice architecture reduces complexity, increases flexibility, increases reusability as compared to a monolithic architecture.       API(Application Programming Interface) According to NIST definition, an API is, A system access point or library function that has a well-defined syntax and is accessible from application programs or user code to provide well-defined functionality. API provides a well-defined set of protocols, routines, and rules for a system so that another system can communicate with it. An API specifies how software components should interact. Documentation on how to…

Understanding Cloud Deployment Models. Cloud Part – 2
Cloud , Uncategorized / November 21, 2019

For part 1 of this series visit the following link What is Cloud Computing and Why? Cloud Part – 1   Cloud Deployment Models represent the types of cloud environments used by business organizations depending upon access, ownership, and size. There primarily  4 types of cloud deployment models Public Cloud Private Cloud Hybrid Cloud Community Cloud All these models provide various IT Resources as services Public Cloud A Public cloud is a publically accessible cloud environment. Resources and their maintenance is run by Cloud Service Provider (CSP) for a cost. The services are scalable, flexible and used by multiple organizations. Major Public Cloud Service providers are Amazon, Google, and Microsoft.   Some of the major negatives of public cloud services are Ownership of data rests with the cloud service providers. No exclusive custody. Limited control as a whole of the resources is handled by the service provider. Fear of lack of security. Multiple organizations access services.     Private Cloud A private cloud environment is owned and used exclusively by a single organization. A private cloud enables and organization to provide centralized access to IT resources for different parts/sections/departments of a business organization. Private cloud service models can be broadly divided into…

Understanding Cloud service models IaaS, PaaS and SaaS – Cloud 3
Cloud , Uncategorized / December 3, 2019

You might have heard acronyms like IaaS, PaaS, SaaS, what do they actually mean? what are cloud service models?. This is the third part of the Cloud Series and aims to provide an answer to the above questions. This article will provide you with an overview of cloud service delivery models so that you can choose which service model is best suited for your business application.   Cloud service models Cloud service models are models, based on which pre-packaged combinations of IT resources are delivered to the customer as services, by the cloud service providers(CSP). The three cloud service models following which the services are offered to the customers are Infrastructure as a service(Iaas), Software as a service(Saas), Platform as a service(Paas). Serverless is a cloud service execution model.   Other approaches by which CSPs provide service to the customers are Backend as a Service Backup as a Service Banking as a Service Blockchain as a Service Business Process as a Service Communications as a Service Compliance as a Service Consensus as a Service Container as a Service Crime as a Service Crypto as a Service Data as a Service Database as a Service (DBaaS) Datacenter as a service (DCaaS) Desktop…

Difference between tilde (~) and caret (^) in package.json, Semantic Versioning of npm packages and npm audit for vulnerability fixes
interview questions , Uncategorized / November 27, 2019

In the package.json files of  Node.js applications, the dependencies are added specifying their version. Sometimes these version numbers can be preceded by tilde (~) and caret (^) characters. What do they actually intent and what is the difference between them?     Semantic Versioning of npm packages Consider a version of a package like 1.2.3                It is of the form MAJOR.MINOR.PATCH MAJOR in version is updated when major change, which can affect compatibility is made and the new one might not have backward compatibility. MINOR in version is updated when a minor change is made in a backward-compatible manner. PATCH in version is updated when backward compatible bug fixes are made. Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format. Caret will install packages with version updated until just before the next major and tilde will install packages with version updated until just before next minor. We will see this in detail below   caret (^) character in the version  caret (^) character in version number means that the package version installed will be updated up to the latest minor and its patch, of the major. For…

Understanding Map object in JavaScript

Map Hold key-value pairs Remember the order of insertion. Can have objects or primitive values as key or value. Map is a JavaScript object which can hold key-value pairs  and remember the order of insertion. Maps inherit from  Map.prototype. Map.prototype.constructor returns the constructor function that created an instance’s prototype. A new Map is created using the map constructor in the following way.

We can set key-value pairs using the set method

You can see here that  Map remembers the order of insertion.  Maps can have objects or primitive values as key or value. For example, see the following map which has an object as key and object value. Here we set object key-value pairs using the set method and retrieve it using the get method.

  Now get the object value belonging to object key using get method

  Read more on Map.prototype hereMap

Q: Handling errors while using Async/Await (JavaScript ES8)

This article aims at providing an insight into handling errors while using async-await. In the below example, a  function TestPromise will return a promise.The promise will give an error and get rejected if the value of the variable budget is less than 20000. The promise will always get rejected as we initialize the value of  budget to be 10000. A function calltestAPromise calls the function TestPromise.  

As shown above function calltestAPromise will call TestPromise and handle the promise it returns with .then  and .catch, an error will get caught in the .catch which will handle the rejected case. The above promise will get rejected with an error.   Now change the function calltestAPromise to be an async function which will await for the promise to get resolved or rejected.

Now, the promise returned by TestPromise will get rejected with an error. The error won’t be handled and the promise rejection will be left unhandled. If the promise gets rejected, the code will never reach the console.log. Handling the error on a promise can be achieved by wrapping the block of code inside a try-catch. The rejected error on promise will be caught by the catch.

The catch of try/catch will catch the error of the promise rejection and the error will be handled in…

Beginners guide to installing and setting up MongoDB and GUI for MongoDB in Windows Machine
MongoDB , databases , Uncategorized / September 26, 2019

This is a step by step tutorial for installing MongoDB and setting up a GUI for MongoDB on Windows OS   Step – 1 Check whether MongoDB is already installed in the system To check whether MongoDB is already installed in the system, and the PATH variable is configured, use the following command. This will output the version of MongoDB .

The following command will output the Mongo shell version

If installed and configured, the output will be something like db version v3.4.14 –          mongod -version MongoDB shell version v3.4.14 –           mongo -version If not, the output will be like     Step – 2 Download and install  MongoDB and the mongo shell on Windows machine Go to the MongoDB official site and download the setup file for Mongo and install it on the machine. The default installation folder will be inside program files in your C drive

You can customize your installation and also choose whether to install or not install the MongoDB Compass which is an intuitive GUI by MongoDB Inc. Navigating to the bin folder and running the commands in Step 1 will give you the versions…

Promise.prototype.then() : JavaScript then() method and how to use it
Javascript , Requests , Uncategorized / September 25, 2019

Q:  How to use then() and how to return a promise from a function and use then() ?   A: then() is a method in the Promise prototype that returns a promise and accepts two callback functions. One function is for the success and the other is for the failure case of the promise. If both arguments are not given or are not callback functions, still then the method would not generate any errors. For example, here we create a new promise.

promise .then() exists hence it is a promise. .then() allows method chaining.   Now we will see how to use then to return a promise It is incorrect to use then() this way as it should return inside the then also. Otherwise resolving the promise returned by then will give undefined.

    It is incorrect to use the function without returning the promise returned  by then()

    Returning the promise returned by then is the correct way of returning a promise from a function

    If there is some kind of logic to be applied, this is the correct way of using then()

 

Node.js – tools/packages/practices for building a secure,high performance API with quality code

Contents >Code standard and styling >Security >Performance         In this article, we will take a look at some important aspects to be considered while developing Node.js applications and the tools/packages/practices that can be used to achieve them. Understanding and using these will help you in building a secure web application that is well structured and well documented and has a very high performance. Code standard and styling Tool – Linters(ESLint/JSLint/TSLint) Linters are static code analyzing tools that check for static code issues like styling errors, poorly structured code and unsafe code. Linters help in implementing a certain set of coding rules and helps in avoiding static errors like an absence of strict type checking, mismatched import or undefined variable usage .Static code analysis is analyzing the code for errors/faults in coding rule implementation before running the code. Dynamic code analysis is performed after the running. The most commonly used styling modules are Airbnb/JavaScript and Github/JavaScript.You have to integrate the linting plugin to the editor you are using(eg – Visual Studio Code/Sublime text). The linter will show linting errors like the following.   ESLint and JSLint are used along with JavaScript. TSLint is used with TypeScript. An example…

Check for duplicates in JavaScript Array of Objects
Javascript , Express.js , Uncategorized / July 28, 2019

How to check whether an Array of Objects contain duplicates by key Consider an Array of student Objects with each object having a key id. We have to perform a validation whether multiple objects with the same Id is present in the Array or not.

The above are Arrays of student Objects, one with duplicate id value and one without duplicate id value. To get the  Ids present in the Arrays we need to use the map() Method

  Now we have two Arrays containing all the Id values of Objects.  The first one has unique Ids  and the second one has duplicate Id 42342.   To check for duplicates in Arrays, we can create a set from the array. Sets will only have the unique items in the array

  The second set only has 2 values as one of the values in the Array had a duplicate. So, on comparing the length of the Array and size of the Set  we can determine id  Array has duplicates or not  

  The whole code to check whether an Array of objects contain key-value duplicates will look like this. We can use this logic…

Share this page in social media platforms