Skip to content

NodeJs Introduction#

What Is The NodeJs?#

  • NodeJs is an open source and cross platform run time environment for executing JavaScript codes outside of a browser. While often we use Node to build backend services, also called API's or Application Programming Interfaces.

Node Architecture#

  • Before the NodeJs, the JavaScript code is only used for building applications that run inside a browser. So every browser out there has what we call a JavaScript engine that takes JavaScript code and coverts into code that computer can understand. In every browser, we may have different JavaScript engines. Ex:

    • Chakra is used for Edge
    • SpiderMonkey is used for FireFox
    • V8 is used for Chrome.
  • So sometimes JavaScript codes can have differently in one browser or another.

  • Before the 2009, JavaScript only can be run on Browsers. But in 2009, Ryan Dahl the creator of Node came up with a brilliant idea. He thought it would be great to execute JavaScript outside of a browser, so he took Google's v8 engine, which is the fastest JavaScript engine out there, and embedded it inside a C++ program and called that program Node.

 #zoom

  • So similar to a browser, Node is a runtime environment for JavaScript code. It contains a JavaScript engine that can execute our JavaScript code. But it also has certain objects that provide an environment for our JavaScript code. But these objects are different from the environment objects we have in browsers. For example, we don't have the document object instead we have other objects that give us more interesting capabilities. For example, we can work with the file system, listen for requests in a given port, and so on.

How Does It Work?#

  • Node applications are highly-scalable and this is because of the non-blocking, or asynchronous nature of Node. It means a single thread on Node application can be used for handling multiple requests. So Node applications can serve more clients without the need to throw in more hardware and that's why Node applications.

 #zoom

  • In contrast, Node should not be used for CPU-intensive applications like video encoding or an image manipulation service. In these kind of applications, we have a lot of calculations that should be done by CPU, and few operations that touch the file system or the network. Since Node applications are single threaded, when performing the calculations to serve one client, other clients have to wait, and that's why Node should not be used for CPU intensive applications. It should only be used for building data intensive and real time applications.

Install NodeJs#

See Also#

References#