How to install Node.js

Node.js is a popular runtime environment that allows you to run JavaScript code on the server-side. Here's a step-by-step guide to installing Node.js on a typical Windows operating system and a simple example of running a JavaScript file using Node.js.  Remember that Node.js is not limited to running just simple scripts like the one below; it's commonly used for building web applications, APIs, servers, and more.

Step 1: Download Node.js

  1. Open your web browser and navigate to the official Node.js website: https://nodejs.org/
  2. On the homepage, you will see two download options: LTS (Long Term Support) and Current. It's generally recommended to download the LTS version for stability.
  3. Click on the "LTS" button to download the installer for the Long Term Support version.

Step 2: Install Node.js

  1. Run the downloaded installer (the file will have a .msi extension).
  2. The installer will guide you through the installation process. You can choose the default settings or customize them based on your preferences.
  3. Once the installation is complete, Node.js and its package manager, npm (Node Package Manager), will be installed on your system.

Step 3: Verify Installation

  1. Open the Command Prompt or your preferred terminal application.
  2. To verify that Node.js and npm are installed correctly, type the following commands and press Enter after each:

 
node -v
npm -v
 
 

These commands will display the installed version of Node.js and npm, respectively.

Step 4: Create and Run a Simple Example

  1. Create a new file named hello.js in a directory of your choice.
  2. Open hello.js in a text editor and add the following code:

     console.log("Hello, Node.js!");

     3. Save the file.

Step 5: Run the Example

  1. Open your Command Prompt or terminal.
  2. Navigate to the directory where you saved hello.js using the cd command. For example, if you saved it on your desktop
  3. cd Desktop
  4. Run the JavaScript file using Node.js:
  5. node hello.js
  6. You should see the output in the terminal:
  7. Hello Node.js !