Learn Simpli

Free Online Tutorial For Programmers, Contains a Solution For Question in Programming. Quizzes and Practice / Company / Test interview Questions.

Introduction to NodeJS, and its Features

Node js introduction and its features

Node js introduction and its features, Node.js is a cross-platform run time environment. And it can execute javascript code in it. And Node.js platform runs on a V8 engine that is built by Google. Node js is specially developed for building very high-end scalable network applications. And it’s been single-threaded. Node.js platform can run on Windows, Linux, Unix, Mac OS X.

What are the features of Node.js?
Single-threaded:
Node.js can be executed in an asynchronous approach. Let’s see how the single thread works in Node.js with a below example.

For reading a file, node js
1. Accept the request from the user
2. Sends the task to the event loop
3. While sending in callback function will be registered with the event loop.
4. Now Node.js is ready to handle next request
5. When reading a file is completed, then file content will be served.

Asynchronous and event-driven:
Node.js provides a rich set of libraries for your modules to execute it asynchronously. As explained in the above point, Node.js will pass the request to the event loop and ready to serve the next request. In this approach, Node.js never wait for serving the next request.

var fs = require('fs');

fs.readFile('DATA', 'utf8', function(err, contents) {
      console.log(contents);
});

console.log('after calling readFile');

// synchronous
var fs = require('fs');

var contents = fs.readFileSync('DATA', 'utf8');
console.log(contents);

Super Fast :
Because of the non-blocking execution approach, Node.js will speed up the execution when dealing with reading and write operations of files. Read and write operations of the database or network connection. But this is not the same case when dealing with intense CPU processing activity.

Data streaming applications:
You can develop streaming web APIs. But streams are not introduced in Node.js. They were introduced in UNIX OS.

No Buffering :
Node.js applications will not use a buffer for data. Node.js applications send the output of the data in chunks.

When to use Node.js?
You can use the Node.js platform if you are building following kind of applications

  1. I/O bound Applications
  2. Data Streaming Applications
  3. Real-time Applications
  4. Web REST API
  5. Single Page Applications

When not to use Node.js?
Node.js is will not give a good performance, if you are building following kind of applications

  1. When applications need heavy computation tasks
  2. When applications have event loop blocking

Also, read Nodejs read multiple files in the async approach

2 thoughts on “Node js introduction and its features

Comments are closed.