ASP.NET,C#.NET,VB.NET,JQuery,JavaScript,Gridview,SQL Server,Ajax,jQuery Plugins,jQuery UI,SSRS,XML,HTML,jQuery demos,code snippet examples.

Breaking News

  1. Home
  2. JavaScript
  3. What is Node.js?

What is Node.js?

In the field of web development the popularity of JavaScript is increasing day by day. Demand from the human side is also changing dramatically. The needs come to run the JavaScript on the server side. But we know JavaScript works only client side. Node.js comes to run the JavaScript on the server side. This article explains about the basic overview of Node.js or introduction to Node.js. Summary of the article:
  • What is Node.js?
  • History of Node.js
  • How to Install Node.js?
  • Sample Program in Node.js.
  • Why use Node.js?
  • When to use Node.js?
  • When not to use Node.js?
What is Node.js?
Node.js is framework of JavaScript. But it is different from the JavaScript. Because, JavaScript is a client-side programming language that runs on the browser. Node.js is a server side JavaScript language. Node.js applications are written in JavaScript language and they are cross-platform. Node.js is asynchronous. Normally any programming language executes line by line. That’s why when a function has lot of SQL queries that takes more time to execute then client may wait to go next line. But in node.js next line can be executed at the same time that’s reduce extra time.
History of Node.js
Node.js was developed by Ryan Dahl in 2009. It is written in C, C++, JavaScript

How to Install Node.js?

To install Node.js at first we need to download it. We can down it from here. Here all types of source file are available for windows, mac, linux etc. After that install it as like normal application based on OS. For windows go to the downloaded file and double click it. Follow all the process. If every things are ok Node.js will be installed.
To check open the terminal and type
Node –v
Here we can write JavaScript code. For example type the following code and press enter:
console.log(“Hello World”)
It will show Hello World.
Sample Program in Node.js
In Node.js we can write any JavaScript program. Suppose we want to make a function that will take two integer value and will return their sum. Write the following JavaScript code
function add(a,b) { return a+b }
Press enter and call the function as like
add(4,5)
It will return: 9
In this way we can develop applications in Node.js.

Why use Node.js?

Reasons to use Node.js:
  • It is very lightweight and fast.
  • It runs JavaScript, so we can use the same language on server and client side.
When to use Node.js?
We can use Node.js in the following cases:
  • For any real-time applications: online games, collaboration tools, chat rooms, or anything where any changes need to be seen by other users immediately
  • For single page apps (Mobile Web applications, Web applications in AJAX etc).
  • For small API
  • If our server side code requires very less CPU cycle
When not to use Node.js?
We should not use Node.js in the following cases:
  • For big web sites or web applications
  • If our server side code requires very heavy CPU cycle
Node.js is not always the solution, but it can solve some complex and important problems. So in order to work with Node.js it is better to learn clearly where it is necessary.

1 comment: