What is Node JS

Node JS is open source and cross-platform JavaScript Runtime to run JavaScript outside web browser. Node JS is build on Chrome's V8 engine.

Node JS is asynchronous event-driven JavaScript runtime build for scalable network applications.

JavaScript was meant for web browser only, but using node js, we can use JavaScript outside web browser to build scalable applications.

To learn Node JS, The basic fundamentals of web are required. Please go through our HTML, CSS and JavaScript Tutorial for revision.

Node JS Applications

Node JS is based on Chrome's V8 engine, one of the fastest JavaScript engine. Node JS use asynchronous event-driven runtime. Node JS can handle many concurrent connection at one time.

The JavaScript Execution in Node JS is single thread and Non Blocking making Node JS one of the Fastest Backend Server that can handle many concurrent at time with low RAM and best use of CPU.

Node JS based applications

  1. Web Application Development.
  2. Hybrid Apps Development. (Both Desktop & Mobile)
  3. API Development.
  4. Chat Applications.
  5. Streaming Services for Video and Audio.

Node JS Based Web Servers

  1. Netflix
  2. Linkedin
  3. Uber
  4. Paypal
  5. Nasa
  6. Medium
  7. Slack
  8. Twitter

Node JS Based Desktop Applications

  1. VS Code
  2. Brackets
  3. Atom
  4. MongoDB Compass
  5. Whatsapp for Desktop
  6. Facebook Messenger for Desktop

Node JS Performance Secret

JavaScript use Single Thread for execution in a web browser. For long operations like Timers, JavaScript use callback functions. The same way Node JS works. Using this technique, Node JS can handle much more connections than Apache with very low memory.

Apache can handle upto 10k connection. But Node JS can handle even more connections at one time.

Without Callback





With Callback




setTimeout(()=>{ console.log(2)});  // will run after 3

As we can see that there is a callback function in setTimeout function, thus JavaScript will not block here and execute third line first. After main thread is free (after printing 3), now callback function will be executed and we will get 2.

The same way database connections are handled in Node JS. By using Non Blocking approach for long waiting tasks, Node JS can handle multiple connections using a single thread.
See example

Blocking Request

const fs = require('fs');
const data = fs.readFileSync('/data.txt');
console.log("done");     // will run after data      

Non Blocking Request

const fs = require('fs');
const data = fs.readFile('/data.txt',(err,output)=>{
console.log("app running");      // will run first     

It is recommended to use Non Blocking call for file handling in node. Using Blocking call can slow down code performance. So That's how JavaScript being single thread programming language executes very fast just because of callbacks.

Node JS is best for Data-Intensive Applications

The use of single thread and asynchronous event-driven make Node JS best for Data Intensive Applications, like a Web Server where I/O is the biggest issue. Node JS servers best as a web server with very low memory and can server more requests.

Node JS is not best for CPU Intensive Applications where multi-threading is required.

Node Js Vs PHP

Lets Compare Node JS Vs Php as a web server.

Php use Apache Web Server. Apache is Thread & Process Based server where each request is handled by a different thread (process). To assign process to different thread, Apache consumes more memory (RAM).

Node JS is based on Nginx. Nginx is a single thread web server used to handle multiple concurrent request.

Node JS Vs PHP
Features Php Node JS
Release 1995 2009
TypeProgramming LanguageJavaScript Runtime Environment
ApplicationWeb ApplicationWeb Apps, Software Apps, Console Apps
Hosting SupportAll Hosting ServersNeed VPS
Learning ComplexityEasyMedium

Node JS Vs Apache Connections

nodejs vs apache connections
nodejs vs apache connections

Node JS Vs Apache memory

nodejs vs apache memory
nodejs vs apache memory (RAM)

For NodeJS Video Tutorials, Join our Youtube Channel.