Environment Setup for Node.js
Node JS has been delivered in more than 15 significant versions, with some versions speaking to Long Term Support (LTS) discharges – which means they are used for a longer timeframe, roughly 30 months. Whereas other versions have speedier shorter time frames – which implies when another version is delivered, roughly every six months, the earlier version is no longer refreshed.
For setting up a local environment for Node.js, we need the following two software – The Node.js binary installable and Text Editor.
The Node.js Runtime
In this tutorial, we will be using the latest version (14.13.1 current) that is available at the website link given below:
Here, you can download the recommended version for your device.
Note: For this tutorial, we will be using Windows (x64), but the process may vary as per your operating system. However, the result would be the same.
Steps to Install Node.js in Windows
Step1: Once the download is completed, you can Run the Setup.
Step 2: Click on Next to Continue.
Step 3: Accept the Terms & Conditions, & Click on Next.
Step 4: Select the destination folder for installation & Click on Next.
Step 5: Choose the recommended settings, and Get ready to Install.
Step 6: Once Node.js is installed, Click on Finish to complete the setup.
Once you effectively install Node.js, the bin folder will contain the executables as follows:
Text Editor for Node.js
The Text Editor is a software that is used to type the program. Some examples include Notepad, Notepad++, Brief, OS Edit command, Visual Studio Code and many more. Apart from Text Editor, there are Integrated Development Environment (IDE) for typing the codes. An integrated development environment is a product application that gives complete services to developers for program development. An IDE ordinarily comprises at least a source code editor, build automation tool and a debugger.
Here, we will be using the Visual Studio Code that is available for Windows as well as MacOS and Linux. You can also download and install the stable version from the official website: https://code.visualstudio.com.
Verify the installation: Executing Files
To check whether the node.js is installed correctly and entirely on our computer, we will follow a set of procedures.
Step 1: Open Command Prompt (or Terminal in MacOS or Linux).
Step 2: Type the following command: node -v, and Enter.
Executing the above syntax will give an output as follows:
Similar to all other fundamental executables in programming language run-time environments, the Node.js node command has an abundance of alternatives and environmental factors, you can use to adjust its default performance, which incorporates practices for examining safety, reporting and test highlights, in addition to other things.
If we execute node with the -v flag, which stands for version, will provide an output in terms of version (e.g., v14.13.0).
We can also execute –help flag after node command to see a list of more than 50 Node.js options and more than 15 node.js environment variables.
Node.js First Example
As we’ve talked a lot about Node.js, let us use it for executing a simple program.
Create a js file named hello.js in any text editor having the following code:
/* Printing' Hello World!' in node.js*/
Now execute hello.js using Node.js interpreter to see the output –
$ node hello.js
It will give you an output as follows: