Node.js – Welcome to Non blocking environment

Introduction

  • In this article I will focus on fundamentals of Node.js platform
  • I will describe how to prepare development environment for Node.js
  • Also I will explain What is Node.js, Why Node.js and How to start with Node.js

What is Node.js ?

  • Node.js platform is built on top of Chromes Javascript runtime for easily building fast and scalable network applications using JavaScript at server side
  • Node.js is fast because its written in C language
  • It uses non-blocking event driven model with callbacks that makes it lightweight and efficient
  • Ideal for data intensive services across distributed environment
  • Following are the important pointers in Node.js
    • Events
    • Async I/O
    • Streams
    • npm
    • TCP/UDP
    • Single-Threaded
    • Cluster
  • We mainly leverage JavaScript language for client side programming in Web development; However with Node.js we can develop Server side applications with JavaScript language
  • Very important Node.js is not web framework
  • Also Node.js is not for Multi threaded applications
  • Reference : https://www.nodejs.org

Why Node.js ?

  • Node.js uses JavaScript as programming language so we can use existing JavaScript skills; This helps to accommodate learning curve
  • With Node.js we can write non blocking code which is ideal for data intensive tasks
  • We will get nice support from Node.js community

How Node.js ?

  • I will consider configuration of Node.js on Windows machine
  • Please browse https://www.nodejs.org website to download latest Node.js binaries as follows

Node

  • Once downloaded you need to run wizard based setup to install Node.js as follows

Node

  • Please check if Node.js installation is done please refer following steps
    • Open command prompt as follows

command

  • After that enter command “node” as follows then you should get console for Node.js; this means Node.js installation is done

Node 01

  •  I will also show how to check console.log to check installation of Node.js as follows

Node 02

 

Difference between Blocking code ( Synchronous code ) and Non-Blocking Code (Asynchronous code )

  • Its important to interpret difference between Blocking code and Non-Blocking Code to leverage Node.js
  • Please refer following example to demonstrate  Blocking code and Non-Blocking Code
    • Blocking Code
      • Read file from filesystem
      • Process and save to database
      • Next steps
    • Non-Blocking Code
      • Read file from filesystem
        • whenever process done then save to database
      • Next steps
    • Diffrence is very easy to interpret that Blocking Code means serial execution and Non-Blocking Code means parallel execution

Node.js Hello world application

  • We can use any text editor to create Node.js Hello world application
  • I have written simple http request and response Hello world application as follows

Node

  • Code is self explanatory with comments
  • Please run Command prompt to execute above code and enter the Node.js file path as followsNodeTest
  • Now open url http://localhost:8080 in your borwser you will see following output

Node Output

 

I this article we have discussed what is Node.js with Hello world example

Hope this helps

2 comments

  1. Hi ketan,
    Its good article I will try these simple steps.
    Please keep posting good articles like this.

Leave a Reply

Your email address will not be published. Required fields are marked *