What is Node.js and REPL
What is Node.js and REPL
What is Node.js ?
Node.js eliminates the waiting, and simply continues with the next request. It runs single-threaded, non-blocking and asynchronous programming.
All programmer knows computer only understand machine language (binary language). It cannot understand any other language like- English, Japanese or other. When we are writing a program, a backend program (compiler) convert it into machine language. after that computer understand it and give response it also in machine language. Here compiler also convert it into English language and send to client.
History of Node.js
Synchronous Programming vs. Asynchronous Programming
In Synchronous Programming execute one code/request at a time and another code/request are in queue for waiting till first request is not finished. It means Synchronous means you can only one code execute at a time.
In Asynchronous Programming execute one or multiple code / request at the same time and more upcoming request go for execute at the same time. One by one responses will be sent to client, not according to its upcoming queue but its execution taking time. It may be the last request get the response first. So it is called non-blocking system.
It may be understand by an example in Restaurant with two ways :
1. When a customer come and order to waiter for Roti and Matar Paneer. Waiter take the order and go to the kitchen and tell to cook the order and wait for ready the order. Whereas another customer come and wait for waiter to give an order. After sometimes waiter come with Roti and Paneer serve to first customer. After that it take order from second customer .... and so on with all the customer. This is Synchronous Processing.
2. When a customer come and order to waiter for Roti and Matar Paneer. Waiter take the order and go to the kitchen and tell to cook the order for ready. After that waiter take second, third and other order from other customer. He is not waiting for ready the first order. Waiter give the second, third and all order to cook also. Waiter serve the order one by one to customer, which is ready by cook first at the same time. This is Asynchronous Processing.
Why Use Node.js ?
Node.js is fast, lightweight, efficient and an open source, server-side script which run on the Google V8 engine. It support asynchronous mode of operation, event driven I/O rather than using the traditional threads for each process.
Cross-platform compatibility: Node.js is very easily adjustable with various platforms like- Windows, Linux, Mac OS X, Unix, and mobile platforms.
Asynchronous / Non-blocking single thread: Each task in Node.js requests stack are simultaneously executed. Node.js does it all in a single thread. Each API of Node.js library is non-blocking.
Event-driven Programming : In programming context, events are any action made by a user, such as click, double click or any other key action by user. But here in Node.js event means are also same but a bit feel like changed, A server built with Node.js uses a notification mechanism called “Events” to receive and track responses of previous API requests.
When Use Node.js ?
Complex Single page applications (SPAs) : Now a days Single Page Applications (SPAs) are the more popular in web development market. Which an entire applications are built in a single page. Node.js is a good fit for building social networking platforms, dynamic websites, and mailing solutions.
Real-Time Chats : As we know Node.js offers advanced functionalities like Asynchronous / Non-blocking and all requests manages in single threaded, made it faster processing communication. So real-time chatting make easy and faster than used with other technology. Resultant, during chatting live transmission of text, video, or audio messages from a sender to a receiver are fastly very easier .
Data Streaming Applications : Node.js is excellent for the development of streaming applications thanks to its native Stream API. It has an interface of readable and writable streams that can be processed and monitored very efficiently.
Giants like Netflix welcomed Node.js to serve 190 countries and 100+ million hours of streaming across 120 million users and counting. Node.js has a definite edge on this as the processing files at a super-fast speed and feather-light encodes and uploads.
IoT (Internet of Thing) application development : In the recent decade, web application are more popular over the internet. Internet is a network of devices such as sensors, beacons, actuators, and any other items to send and exchange data. IoT may consist of thousands of such devices, which makes it challenging to manage requests and data streams from and between the devices.
Node.js event-driven server architecture and asynchronous processing relevant heavy I/O operations on IoT networks. Furthermore, Node.js operates on writable and readable channels and streams, which is why it is the most suitable platform for IoT app development.
NPM (Node Package Manager)
Node Package Manager is also called as "npm", which is the default package manager of Node.js. When we are installing Node.js, npm has been already installed. In the Node.js library it contains many useful modules. After that, more modules are downloading as our needs.
Now you can also check "npm" like as "node" at command prompt (CLI)
What is REPL?
Just like window provide a command line interface (CLI), in CLI (c:\users\Bhagwan Babu>_ ), Ubuntu provide terminal, in terminal Bash shell (user@ubuntu:~$) for execute some command for run some operation, like create, read, print, etc.
Node.js also provide and command line environment called it REPL (Read Eval Print Loop). REPLs provide an interactive environment to explore tools available in specific environments or programming languages.
How to run REPL ?
After installation of Node.js, when you write code "node" and execute it, a new prompt show (>), here all REPLs command will be executed.
After that if you want to know REPL supported command that are run on REPL prompt (>). Type on > .help
.help command displays some command for run on REPL (>) environment.
In this article, we are studying about Node.js, when we use Node.js? why use Node.js? What is v8 engine? Synchronous vs Asynchronous programming? What is NPM? What is REPL? What is the way to run REPL.
You can also read about what is MERN?
In the further article, we are studying more about programming in MERN stack.