How to install Node.js in Windows? MERN Stack online course

How to Setup Node JS in Windows?

Node.js is easy to get started and can be used for prototyping and agile development. It can also be used to build superfast and highly scalable services. Here, a trainer from Web Development institute in Delhi, is going to make you learn about what Node.js is? What are its important components and how to set up Node.jshttps://g.co/kgs/dqjY6q7 .This will give you the foundational knowledge required to get started with backend development with Node.js.

What exactly is Node.js in MERN Stack development?

Let us consider a scenario where a user interacts with a web application. The user only interacts with the front end of the application but there is a lot of work that goes behind it.

In a web application, there is a front-end, a server and a database. The front-end is developed using JavaScript and frameworks like Angular and React at the same time, the server is built on Java, PHP or Node.js and the backend database that stores data usually consists of MySQL or MongoDB.

Node.js is an open-source cross-platform JavaScript runtime environment for running server-side applications. Node.js is designed to build scalable network applications. It is used to develop IO-intensive web applications like video streaming sites, single-page applications, online chatting applications and other web applications. It is used by large established companies and newly minted startups.

Node.js allows us to run JavaScript on the server.

Why Node.js is so popular in web development in 2024?

Being built on Google Chrome’s v8 JavaScript engine, its library is extremely fast in code execution.Node package manager has around 50,000 bundles for developers. So, whatever functionality is required for an application can be easily imported from NPM.

All APIs of the node.js library are asynchronous i.e. non-blocking. It means a node.js-based server never waits for an API to return data. Node.js dramatically reduces the processing time while uploading video and audio files. It is also an open-source platform and is easy for beginners in web development. The above reasons more than justified the popularity of node.js.

How to set up node.js in your windows 11?

  • To install the latest version of node.js, you need to go to the browser; search “node.js” official website and hit enter.

download node.js

  • Once you are here, you can see the LTS Version of node.js to download.LTS stands for long-term version which we are recommending you all to install.

node.js in windows 11

  • Choose “window installer”, if you are doing it for windows.  Do not install the current version as if you’ll be installing react, angular or next.js later, then you might see some issues.

  • Navigate to your “download directory” and open the node.js file which is already downloaded.“Welcome to node.js” will appear and hit “next.”

how to install node.js in windows 11

  • The “license agreement” will appear. We’ll check the box to accept the agreement.
  • This is where our node.js is going to be installed. We’ll keep this default and click on next.

mern stack online course

  • All packages that will be installed along with node.js will appear in the dialogue box.

mern stack course in delhi

  • Next, we will Hit “Install” and there you go.
  • It will ask you for administrative privileges and once you provide permission, it will directly start installing our node.js. Wait until your file is installed completely. Choose “finish”.

Verify Node js installation in windows

  • It’s time to verify the installation.
  • Search for “cmd” > choose “command prompt.”
  • Open the command prompt > type “node – v” and hit enter. Then, you can see the latest downloaded version of the node on the screen.

node commands for windows

Let’s verify our NPM versions as well. Type “npm –version” and when you hit the enter button, you will see your NPM version properly which indicates the right installation of node.js.

npm version check

How to write your first code?

To start writing our first program, we need to install Visual Studio Code first.

  • Follow the steps below to get the VS code in your system.
  • Open your browser > Go to the official website of Visual Studio Code > Download 

  • We are working on Windows and will choose Window installer. Furthermore, we will create a new folder and open the same folder in VS code so that we can easily run our scripts and see the magic of node.js.

nodejs in vscode

  • We will create a file Index.js in VS code. 

node js first program

first node js code

  • Now, let us try to print our basic program i.e. Hello World.  We will simply write console.log (“Hello world”) 

node js program tutorial

  • Open the terminal and run the code. 

node js beginner tutorial

  • You will see node “file name” automatically written in the terminal.  You can also try writing “node index.js” and “node index” to print your desired output. 

node js index file

“Hello world” will be printed on your screen.

Some important components of node.js

Chrome’s V8 engine

The JavaScript code we write cannot be understood by the computer. We need what is called a JavaScript engine.

A JavaScript engine is a program that converts JavaScript code that developer’s write into machine code that allows a computer to perform specific tasks. In simple terms, a JavaScript engine can execute JavaScript code. JavaScript engines are typically developed by web browser vendors and every major browser has one.

 Following is the list of the different JavaScript engines for each major browser.

  • V8:  This is the open-source JavaScript engine developed by Google for Chrome.
  • Spider Monkey: This is the JavaScript engine covering Firefox.
  • JavaScript Core: This is the JavaScript engine developed by Apple for Safari.
  • Chakra: This is the JavaScript engine for the original Microsoft Edge.

In this list, our interest lies in the V8 engine by Google.

Let’s spend a few minutes to see what we can understand about it.

V8 is Google’s open-source JavaScript engine. We have just learned that JavaScript engine can execute JavaScript code.  V8 implements ECMAscript as specified in ECMA-262. The code for V8 is written in C++ not in JavaScript and is used in Google Chrome.

V8 can run stand-alone or can be embedded into most applications. In other words, you can use theV8 engine as is, to execute some JavaScript or if you have your own C++ program you can embed V8 into that program.

By embedding V8 into your own C++ application, you can write C++ code that gets executed when a user writes JavaScript code.

Libuv

Libuv is a cross-platform open source Library written in C language. This layer gives node.js access to the underlying computer operating system, file system, networking and more.

Why do we need Libuv?

Libuv handles asynchronous non-blocking operations in node.js. It abstracts away all the complexity of dealing with the operating system. It performs all this by using two very important features namely thread pool and event Loop.

Thread pool and Event loop

In simple terms, the event loop is responsible for handling easy tasks like executing callbacks and network I/O while the thread pool is for more heavy work like file access or compression.

The Event loop is where most of the work is done in your app.  It is really the heart of the entire node.js architecture but here is the catch.

The event loop can then automatically offload heavy tasks to the thread pool. All this happens automatically behind the scenes. It’s not us developers who decide what goes to the thread pool and what does not.

Some tasks are too heavy and expensive to be executed in the event loop because they would then block the single thread and this is where the thread pool comes in.

MODULES

Modules are like JavaScript libraries which are used in a node.js application. To include a module in a Node.js application, we will use the require() function. The name of the module to be included is passed as a parameter to this function.

const http = require(‘http’);

This code includes the HTTP module, which allows the application to create an HTTP server and handle HTTP requests and responses. Node.js application has many modules to provide the basic functionality needed for a web application. Some of them could be http, util, fs, url, Querystring, stream and zlib. We all have come a long way and understood a lot of thing about Node.js with a better clarity.

But still if you find yourself in trouble, you can take out help of mentor by enrolling into online mern stack course or offline web development course in Delhi by ESS institute. 

Learn more about SQL basics here and Check the top 45 questions for web design job interview