Signup/Sign In
LAST UPDATED: MAY 7, 2021

How to install NodeJS in your system

The installation of the NodeJS platform is the first step in creating your NodeJS applications. The NodeJS architecture is compatible with a wide range of operating systems, including Windows, Ubuntu, and OS X. After installing the NodeJS platform, you will begin developing the first NodeJS applications.

Getting up and running with NodeJS, as any other programming language, framework, or tool that isn't included with Windows, needs some initial configuration before you can start hacking.

In this article, we'll look at how to install NodeJS on Windows. Once we've finished the tutorial, you'll be able to go on to the next level with NodeJS.

Let's dive straight in!

Installing NodeJS

NodeJS can be downloaded from the official website at nodejs.org. You will provide precompiled binaries and installers for Windows, Mac OS, and Linux. Using an installer is the safest option.

Step 1) Download NodeJS Installer for Windows

nodejs website

As shown in the above picture, download the 32-bit/64 bit according to your system requirement.

Step 2) Run the installation

To begin the installation, double-click the downloaded .msi file. To begin the installation, click the Run button on the first screen.

run

Step 3) Continue with the installation steps

To continue with the installation, press the "Next" button on the next screen.

installation button

Step 4) Accept the terms and conditions

Accept the licensing agreement on the next screen and then press the Next button.

agreement

Step 5) Set up the path

First, specify the location of the NodeJS installation disc. After the download, this is where the NodeJS files will be stored. To continue with the installation, click the Next button.

nodejs setup

Step 6) Select the default components to be installed

Accept the default components and move on to the next step by clicking the Next button.

custom setup

Step 7) Start the installation

To begin downloading NodeJS on Windows, go to the next screen and press the Update button.

ready to install

Step 8) Complete the installation

To finish the installation, click the Finish button.

finishing up

Running JavaScript code using NodeJS

We have accumulated a good understanding of NodeJS and We will begin tinkering with the JavaScript engine until we understand how it operates.

Your original JavaScript code will almost always be in a .js format. We need to send the interpreter the whole file content at once, rather than one line at a time.

In the above example, you can observe we did create a hello-world.js file and there's a hello function present in it. After it was specified in the same file, this feature is named. We used the terminal to run the command node./hello-world.js, which would pick up the hello-world.js file from the directory where the terminal is open. It's not mandatory to add the .js extension to the file path because the node only performs the execution of .js files.

Packages in NodeJS

A package is nothing more than a directory containing a set of components. The most important aspect of a node package is that it should be possible to import it from anywhere in the program without specifying a relative or absolute direction.

The import route will change if our.js files are nested. Let's pretend we have an src directory with compute.js in it. If we need to import the lib kit, we'll go to../lib.

 lib/
|   index.js
|   math.js
 src/
    compute.js // require( '../lib')
    deep/
       nested.js // require( '../../lib')

Tio avoids the cumbersome process of tracking the nested files we need to copy the lib directory within the node modules directory. As a result, require('lib') would refer to the lib directory inside node modules. Now you might have a question how does Node know the directory is? It doesn't. When we import a package, it looks for it in the current file path's node modules directory (where the import statement is written). If the node modules or package directories are not found, it conducts a similar scan in the parent directory. If it's unable to find the package, it throws Error: Cannot find module ‘lib’.

Conclusion

Finally, here comes the end of the tutorial, now that you have installed node js and you're ready to sharpen skills and congratulations you're one step closer to becoming an awesome NodeJS developer.

Happy Learning!



About the author: