Monday, March 11, 2019

Node JS

Node JS


 💥 Node Js is an open source, Cross-platform run time environment for developing server-side and networking applications. This applications written in Javascript , and can be run within the Node.js run time on OS X, Windows.


  • NodeJS Developed by Ryan Dahl. it created with the aim of creating real-time websites with push capabilities. it runs the V8 Javascript Engine, the core of google Chrome, outside of the browser. It is app is run in a single process , without creating a new thread for every request. Node.js provides a set of asynchronous I/O primitives in its standard library that prevent Javascipt code from blocking and generally, libraries in Node.js are written using non-blocking paradigms, making blocking behavior the exception rather than the norm.
        Now we are going to see about the features of the NODE.JS 👇

Features of Node.js


  • Very Fast:- Being built on Google Chrome V8 JS Engine, Its library is very fast in code execution.


  • Asynchronous and Event Driven :-  All APIs  of Node.js library are asynchronous ,that is non-blocking, It essentially means a Node.js based server never waits for an API to return data. The server moves to the next API after calling it and a notification mechanism of Events of Node.js helps the server to get a response from the previous API call.

  •  No Buffering :- Its applications never buffer any data.

  • License:- Node.js is released under the MIT license.



Who uses Node.js? 🤔

  • Some Well-known Resources says that following application are using Node.js
      eBay, PayPal,Uber,Yahoo and Yammer etc




Advantages Of Node.js 😀


  • Ability to use single programming language from one end of the application to the other hand.

  • Support for common tools like Unit Testing.

  • Performance increased via caching modules into memory after the first use.

  • Easily extensible.

  • NodeJs applications are easy to scale both horizontally and vertically.



Disadvantages Of Node.js 



  • Not suitable for computationally intensive tasks.

  • Asynchronous programming model is complex and synchronous model.

  • Even though there are Number of libraries available , the actual number of robust libraries is comparatively low. 


  

Hello World in Node.js using WebStrom 🏃


  • Check the node version of the machine by using following command
               node -v



  • Create a new project and named it (In my case it is NodeJS)

  •  Create a file named HelloWold.js

  •  Add a console.log command to print the String message.
              console.log('Hello World');


  • Open the cmd navigate your project path 
               cd<your project-path>

  • Now enter the following command in the cmd and see the output is there.
               node HelloWorld.js








Use OS system Library



  1. Import the OS system Module to your file
              const os=require('os');

    
     2. Obtain System Architecture, platform and number of CPU's from the OS module   and print them to the console.


          console.log('OS :'+os. platform());
          console.log('CPU :'+os. cpus().length);
          console.log('Architecture :'+os. arch());







3. Run application and check the output.






Node Js is a very powerful javascript based platform built. I touched here a very basic knowledge and stuffs about the Node.js. I hope it might be useful some how for the beginners.


Feel free to share your feedback and comments below.

Thank you for being here and keep Reading.... 😃✌





Tuesday, February 19, 2019

S.O.L.I.D

S.O.L.I.D






  • SOLID Principles is a coding standard that all developers should have a clear concept for developing software in a proper way to avoid a bad design. this concept was created by Robert C Martin and is used across the object oriented design spectrum. When the programming developer builds a software there are some points make bad design. They are , the code can become flexible , small changes in the software can result in bugs. For these points we need to use the SOLID principles. 😇

  • It takes some time to Understand , if you write code this principle we will improve many good things and improve the code quality. 

 Single Responsible Principle 


  • A class should have one and only one reason to change, meaning that a class should have only one job. This is not only about a class it what we consider as  unit. Well lets take the class which does the following
  1. Open a Database Connection
  2. Fetch Data from Database.
  3. Write the data in an external file.
The issue with this class is that it handles alot of operations. Suppose any of the following changes will happens in future.

  • New Database
  • Adopt ORM to manage queries on database.
  • Change in the output structure.

So in all the cases the above class would be changed. Which might affect the implementation of the other two operations as well. so ideally according to "Single Responsible Principle" there shpuld be three classes each having is good.




Open and Close Principle

  • Objects or entities should be open for extension, but closed for modification. The simple means that a class should be extendable without modifying the class itself.
👉open for extension
This ensures that the class behavior can be extended. As  requirements change, we should be able to make a class behave in new and different ways, to meet the needs of the new requirements.

 👉Closed for Modification

The Source code of such a class is set in stone, no one allowed to make changes to code.


  • For Example, Just assume We have X class which is developed by Xman. If the developer Yman wants some modification on that then developer Yman should do that easily by extending A class. BUT NOT MODIFYING CLASS A.



Liskov substitution Principal

  • Every subclass or derived class should be able to substitute their parent or base class. 
  
Example:- 

Lets consider we have a class called Animal.



Now lets consider that Class Dog and cat extends the class Animal.




In our code we were using Animal object we must be able to replace it with Dog/ Cat without exploding our code. What do we means here is the child class should not implemented code and it is replaced by the parent class then the application will stop running.




If the above class is replaced by Animal then our Application will crash.



Interface Segregation Principal

  • Clients should not be forced to implements methods they do not use.
Example:- 

👉 Lets says we have an interface called Animal, which would have eat, sleep, and walk methods. This would mean that we have a monolithic interface called Animal, because some animals can fly. Breaking this monolithic interface into smaller interfaces based on role, we would get canEat,canSleep and CanWalk interfaces.  species would be a combination of roles , instead of being characterized as an animal, which would not necessarily be the best description.We favor composition by separating by roles and Decoupling by not coupling derivative classes with unneeded responsibilities inside a monolith.



Dependency inversion Principal

  • Higher level modules should not depend on lower level modules, but they should depend on abstractions.

  • Think three tier architecture. Business Logic layer Depends on the Database access layer.


  • It means that we should be having object of f interface which helps us to communicate with the concrete classes. What do we gain from this is, we hide the actual implementation of class A from Class B. So if class A changes, class B doesn't need to care or know about the changes.

I hope this blog is very useful when we design the software. 💻


feel free to comments and give feedback.. Thank you for being here and keep reading... 😃✌


Webservices — C# 👩🏻‍💻

  Webservices — C# 👩🏻‍💻 There are a lot of definitions defined about web services. In simple terms, The Web service is any software syste...