4

How to install Node Js in windows

[Social9_Share type="horizontal"]
When I started learning Node JS I was totally confused as where and how to start. Of course there are many tutorials for learning Node JS. My intention to start this Node JS tutorial series is that I want to share what I  have learnt and am learning in Node. This will surely be helpful for beginners  as I am trying to put the concepts in easy English  rather than using technical jargon words Note: You must know basic JavaScript to learn Node JS Now let’s get started with Node JS

Part-I Getting started with Node JS

  1. What is Node JS?
  2. How Node Works?
  3. Download and install Node

 

What is Node JS?

Node JS is a server-side JavaScript platform which is used to build fast, scalable network applications. Node JS runs on Chrome’s V8 JavaScript engine and makes it faster.

Node uses an event-driven non-blocking I/O model that makes it efficient for developing Data Intensive Real Time (DIRT) applications.
To know how node works, let us learn about event driven programming

Event Driven Programming

In event driven programming the flow of execution is driven by events. Events are handled by Event Handlers or Callbacks. When an event occurs(user clicks a button, text field losing or gaining focus), the functions that are invoked are called as Callback functions.

Callback Functions are passed as parameters into other functions. They are called and get executed inside these functions

Example

In JQuery, you write

Here the function within the click method is a callback function. This function will be executed, only when the button is clicked.

Assume in a web application, you want to process a request and generate a response after running a database query. Let us see the scenario in case of blocking IO and non-blocking IO.

Blocking I/O

An Example for blocking IO

In this example, the thread or the process waits, till the backend database work is completed and returns back with the output(result). Then with this output, doWork method will be called. This is called as Blocking I/O as the thread waits, till the work is done.

Non-Blocking I/O

An Example for Non-Blocking IO

Here, you are using a method processDBRequest which takes 2 parameters. The first parameter is the query to the database and the second parameter is a callback function.

Here, the thread will not wait for the outcome, but will continue with the flow of the program, and prints “Hello World”. Once the database work is done and returns back with the result, then the callback function will be invoked. Now, the method doWork() will be called. This makes the whole procedure asynchronous.

You might be having multiple similar methods, all running in parallel. Their callback methods will be invoked accordingly, once the method completes the IO operation and returns with the result. This is a feature of Node JS.

How Node Works?

Node uses event driven, non-blocking I/O programming model. The JS Engine runs the request and then tells what to do when the response returns. In the meantime, your code is free to start processing other incoming requests or do any other task it might need.

In this type of programming, current process will not block when it is doing I/O. So, several operations can run in parallel and the corresponding callback function will be invoked when the operation finishes.

Event Loop

Event Loop is a construct in event-driven programming style. It performs two operations in a continuous loop – detecting an event and triggering an event handler. Node’ s event loop will keep on spinning whenever an event occurs , then identifies the event callback and invokes it.

Installation of Node JS in windows

To install Node JS on a windows machine, go to https://nodejs.org/download/. Choose the Windows Installer(.msi)for 32 bits or 64 bits depending on your machine and download it.

install

Once downloaded double click the MSI Installer.  A new window opens.

download

Click Next and proceed. Select Node JS runtime and click next. click Install  button to install Node JS in your computer. Once completed click the Finish button to complete the installation and exit the setup wizard.

setup
Verify the Installation

To check whether node is installed, open command Line(cmd). Type

 

You must get the version of Node JS installed.nodeus   If you get the output as,

 

then Node JS is not installed in your system. To check whether Node JS is available in your path environment variable, in command line  type

 

and check whether node.js and npm  is in environment variable.

npm
If not found, try installing it again.

The Node REPL

Next, in the command line  type

to launch the Node Shell. This is also called as REPL(Read-Eval-Print- Loop). This is an easy way to check node. You can execute JavaScript and see the results immediately. Let’s see an example. Once when you type node in command line, you enter into REPL. Type

 

You will get the output as

 

learnnode

The first line is the outcome of  the statement you have written. Here ‘console’ is the global variable of Node and log is a function to print the output to the command line. The next line prints the return type of the  statement. Every function call or statement or expression has a value associated with it , that is printed in REPL. If the function or expression does not return any value, then ‘undefined’ is printed in the console(which we got now). Few  more examples

toview

To view all the commands of REPL use

 

It will list out all the commands of REPL repl

While writing in REPL , if you see three dots(…) , it means the REPL is still expecting more input from you to complete the expression, statement or function.

1repl

To exit the REPL press Ctrl+D  or use

 

Once done, move on to the next session, to learn how to create a webserver using node js..

Happy Installing Node.

Comments(4)

  1. Reply
    Mridhul says

    Nice post for beginners. Thanks. I have installed successfully node in my system. Waiting for more topics in Node.

    • Reply
      admin says

      Thanks Mridhul. We will be adding more topics in Node js for beginners. Keep visiting

Post a comment