Facebook Pixel

Node.js Installation

Now that you know how JavaScript runs inside a browser, let’s take things a step further and learn how to run JavaScript outside the browser — using Node.js.

What is Node.js?

Node.js is an open-source, cross-platform, and JavaScript runtime environment that allows you to run JavaScript code outside of a web browser.

In simple terms, while the browser lets you run JS on web pages, Node.js lets you run it directly on your computer.

It’s widely used for:

  • Building server-side applications
  • Creating command-line tools
  • Developing real-time apps (like chat apps or streaming servers)
  • Running scripts and utilities

So, Node.js basically brings JavaScript to places where it couldn’t go before.

How to Install Node.js

Installing Node.js is super simple. Just follow these steps 👇

Step 1: Download the Installer

Go to the official Node.js website — https://nodejs.org. You’ll see two download options:

  • LTS (Long Term Support) — more stable, recommended for most users.
  • Current — has the latest features but may be slightly experimental.

Click the version you prefer and download the installer for your operating system (Windows, macOS, or Linux).

Step 2: Run the Installer

Once the file is downloaded, double-click it to launch the setup. Follow the instructions that appear on screen — keep the default settings unless you know what you’re changing.

The installer will automatically install:

  • Node.js itself
  • npm (Node Package Manager) — which lets you install other useful packages and libraries.

Step 3: Verify the Installation

To make sure Node.js installed correctly, open your terminal or command prompt and type:

node -v

You should see something like:

v22.5.1

Above version is installed in my system, it may differ for you. It just means Node.js is successfully installed!

You can also check for npm by typing:

npm -v

If both commands return version numbers, you’re good to go!


Writing and Running Your First Node.js Script

Let’s quickly run a JavaScript file using Node.js.

  1. Open your text editor — VS Code is a great choice (you can download it from https://code.visualstudio.com).

  2. Create a new file and save it as app.js.

  3. Write this simple code inside it:

    console.log("Hello from Node.js!");
  4. Open a terminal inside VS Code (or your system terminal).

  5. Type the following command and press Enter:

    node app.js

You should see this output:

Hello from Node.js!

That’s it — you just ran your first JavaScript file using Node.js!

Running JavaScript Directly in VS Code

If you prefer, you can also run JavaScript directly inside VS Code:

  1. Open VS Code.
  2. Create or open a .js file.
  3. Press Ctrl + Shift + P (or Cmd + Shift + P on Mac) to open the Command Palette.
  4. Type “Run JavaScript” and select “Run JavaScript file in the terminal.”
  5. Your code will execute right in the built-in terminal, and the output will be displayed below.

This method is quick and handy when you’re experimenting with short scripts.