fbpx
tech node

Exploring Node.js and React.js: Essentials for Developers

According to the definition written on the Node.js official website, Node.js is a Javascript runtime built on Chrome’s V8 javascript engine. Here are two things are important-

(i) Javascript Engine

(ii) Javascript Runtime

Let’s see what Javascript Runtime is. Node.js is not a programming language, it is a runtime. There is a difference between runtime and programming language. For example- JavaScript is a programming language. It was invented to establish dynamic functionality in a web browser. HTML builds the body of a browser and CSS gives color to it. But they can’t do anything more to the browser—that is why they are not programming languages. 

Let’s see how Javascript was developed. The developers had to do two tasks-

 

(i) Design the language and

(ii) Execute the language

To execute the language, the javascript creators developed the javascript engine. This engine takes (something.js) like files and executes them as instructed by the programmer. They developed this engine for the browser so that if the browser has any (something.js) like files it can execute the files through the engine. 

 

So it is now clear that language or syntax are the contents of the JS files, and runtime is what executes the contents. 

 

This runtime can not function on its own. A programmer writes codes for all the elements that are being loaded in a browser. For this, the programmer needs full access to the HTML, CSS, images, etc. of the web page that are called DOM or Document Object Model ( all the elements of a web page). 

 

When we have full access to all these elements we can manipulate the browser as well as the window. Different browsers have different Javascript engines. Among them, the strongest one is the V8 engine by Google Chrome. This V8 engine works on both DOM and window contexts. Then the developer thought that if we take the engine out of the browser then we can perform on other contexts as well. Then they changed the C++ codes and this custom-made open source project was named Node.js. They got full access to the web server or operating system other than only browser. 

 

How Node.js Works

Node.js] Node.js 기초

There are two types of tasks of these Node.js: 

  • CPU-intensive task: When the request of the client can be fulfilled easily by the main server.
  • I/O Intensive task: When the request of the client can not be fulfilled by the main server. It needs the help of another server or data system or multimedia storage. 

In an I/O Intensive task, the server takes time to respond. Suppose, the server has about 5 requests at a time and each request takes 3 seconds then the 5th client will get a response after 15 seconds. So, how this problem can be solved?

Let’s see-

For example, Java uses a Tomcat server and it’s a multiple threaded server. When a client requests to the server, Tomcat assigns a thread for that request and thus responds. But the problem is that Tomcat only has 200 threads which means you can only respond to 200 client requests at a time. So, there is no delay in responding to the first 200 clients. If the request is more than 200 then the client will have to wait for a while. 

 

But JavaScript is a single-threaded language. So, when the request is more than one and it’s an I/O Intensive task, that one thread assigns workers for individual requests and then moves on to another request. That means the thread only accepts the requests and passes them to the workers and the workers respond according to the requests. Thus the client gets a response on time without any delay. 

Node js has two concepts-

(i) Non-blocking I/O: As single threaded it passes requests to workers and the thread remains always free for another request, it’s never blocked. Node js uses libuv for implementing multiple workers (that work like threads) through the system carnel. But when the server gets any request for CPU-intensive tasks the thread becomes busy and that is why Node js is not suitable for CPU-intensive tasks. Node js is mainly used for I/O Intensive tasks when the server has to collect information from system files or other server storage.

(ii) Asynchronous: It means the response or the result showing to the client is not maintaining any serial. It uses a call-back function for this purpose.

 

Features of Node.js

  • Event Loop makes node js perfect for multiple request handling.
  • It’s highly performant because of less CPU use.
  • Blessing fast speed, high performance and flexible because of the use of libuv for implementing multiple workers through system carnel.

 

.

What is React js?

React JS is one of the most popular lightweight front-end open-source libraries. It was developed by Meta formerly Facebook in 2011 and released to the public in 2013. React is not a javascript framework, it is a library which means it’s only responsible for rendering the components of an application. It can be an alternative to the frameworks like Angular or Vue. If you want more freedom when developing your project. 

React js | React JavaScript | React Js UI Framework - K2B

Why is it so popular?

 

Since React is a library, you can easily combine it with any available framework for creating complex functions. React contains a collection of reusable JavaScript codes for UI building. These are called components, the small independent pieces that can be assembled to make a complex user interface. You can think of any pieces you want when building a website UI using React. 

 

For example: If you open Netflix, you will see components like the navigation bar and rows that are contents according to certain criteria. All these parts make up the Netflix UI which you see every time you open the home page. But these components also adopt the user preferences. So, all the top movie sections will be always there but the content will change.

 

How React Works?

Any webpage is divided into some containers like header, upper side menu, lower side menu, middle article, footer etc. These containers are called components of that web page. When you need to change anything in a particular component or container, you can change that only without rendering the whole page again and again which happens in PHP.  For example: If the viewer wants to shift from page 1 to page 2 in the middle article section, then only the middle article section will be rendered and reloaded. That’s why it is faster than others. 

 

 

 

React Features

  • JSX: JSX is the combination of Javascript and HTML. React does not understand HTML but it can understand JSX. JSX is developed in a way that it looks like HTML but it’s not. 
  • Components: The containers and their information on a web page together are called components.
  • One-way Data Binding: When data is transferred from the source to the destination, data binding occurs. The pathway of data transfer is a one-way system.
  • Virtual DOM: Virtual DOM is a complete copy of the actual DOM. When actual DOM is inputted in the browser, it makes a copy of the DOM this copy is called virtual DOM. When a user changes some element, the virtual DOM changes only that element without changing the complete DOM. That’s another reason for its fast performance.  
  • Simplicity: The learning curve of React JS is so much easier. It’s not that hard to learn.
  • Performance: It’s a very lightweight library which means the apps don’t take too much time to function. That’s why the performance is very fast.

 

Final Words

Node js and React js are two powerful technologies that have revolutionized web development. Node js is a server-side JavaScript runtime environment that allows developers to build scalable and high-performance applications. It provides an event-driven architecture and non-blocking I/O, making it efficient for handling numerous concurrent connections. 

React js, on the other hand, is a JavaScript library for building user interfaces, developed by Facebook. It enables the creation of interactive and dynamic UI components through its component-based architecture and virtual DOM. Together, Node js and React js form a robust ecosystem for building modern web applications, offering developers the flexibility, performance and scalability needed to create innovative and engaging user experiences.