Node-js
Node.Js Vs AngularJS: Know the Difference
What is Node JS? Node.js is a cross-platform runtime library and environment for running...
To start building your Node.js applications, the first step is the installation of the node.js framework. The Node.js framework is available for a variety of operating systems right from Windows to Ubuntu and OS X. Once the Node.js framework is installed, you can start building your first Node.js applications.
Node.js also has the ability to embedded external functionality or extended functionality by making use of custom modules. These modules have to be installed separately. An example of a module is the MongoDB module which allows you to work with MongoDB databases from your Node.js application.
In this tutorial, you will learn-
The first step in using Node.js is the installation of the Node.js libraries on the client system. Below are the steps to download and install Node.js in Windows:
Step 1) Download Node.js Installer for Windows
Go to the site https://nodejs.org/en/download/ and download the necessary binary files.
In our example, we are going to Download Node.js on Windows with the 32-bit setup files.
Step 2) Run the installation
Double click on the downloaded .msi file to start the installation.
Click the Run button on the first screen to begin the installation.
Step 3) Continue with the installation steps
In the next screen, click the "Next" button to continue with the installation
Step 4) Accept the terms and conditions
In the next screen, Accept the license agreement and click on the Next button.
Step 5) Set up the path
In the next screen, choose the location where Node.js needs to be installed and then click on the Next button.
1. First, enter the file location for the installation of Node.js. This is where the files for Node.js will be stored after the installation.
2. Click on the Next button to proceed ahead with the installation.
Step 6) Select the default components to be installed
Accept the default components and click on the Next button.
Step 7) Start the installation
In the next screen, click the Install button to start installing Node.js on Windows.
Step 8) Complete the installation
Click the Finish button to complete the installation.
Windows is now recommending that developers use Node.js with WSL2(the Windows subsystem for Linux)
The other way to install Node.js on any client machine is to use a "package manager."
On Windows, the NPM (Node Package Manager) download is known as Chocolatey. It was designed to be a decentralized framework for quickly installing applications and tools that you need.
For installing NPM on Windows via Chocolatey, the following steps need to be performed.
Step 1) Installing Chocolatey – The Chocolatey website (https://chocolatey.org/) has very clear instructions on how this framework needs to be installed.
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object wet.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
Step 2) The next step is to install Node.js to your local machine using the Chocolatey, package manager. This can be done by running the below command in the command prompt.
cinst nodejs install
If the installation is successful, you will get the message of the successful installation of Node.js.
Note: If you get an error like "C:\ProgramData\chocolatey\lib\libreoffice\tools\chocolateyInstall.ps1" Then manually create the folder in the path
Once you have Node.js download and installed on your computer, let's try to display "Hello World" in a web browser.
Create file Node.js with file name firstprogram.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello World!');
}).listen(8080);
Code Explanation:
Executing the code
Save the file on your computer: C:\Users\Your Name\ firstprogram.js
In the command prompt, navigate to the folder where the file is stored. Enter the command Node firstprogram.js
Now, your computer works as a server! If anyone tries to access your computer on port 8080, they will get a "Hello World!" message in return!
Start your internet browser, and type in the address: http://localhost:8080
OutPut
Summary
What is Node JS? Node.js is a cross-platform runtime library and environment for running...
Mostly all modern-day web applications have some sort of data storage system at the backend. For...
In previous tutorials, you would have seen callback functions which are used for Asynchronous...
Introduction to Node.js The modern web application has really come a long way over the years with...
In this tutorial, you will learn Filestream in Node.js Pipes in Node.js Events in Node.js Emitting...
What is Node.js? Node.js is a server-side platform built on Google Chrome's JavaScript Engine. It uses a...