H.dev

Installing Node.js for JavaScript

Hero

Take JavaScript beyond the browser! In this lesson, you will understand the purpose of Node.js and follow step-by-step instructions to install it on your local environment.

  • Prerequisites: Execution of JavaScript
  • Reading Time: 7 min read
  • Difficulty: Beginner

Introduction

Up to this point, we have established that JavaScript runs inside web browsers like Chrome or Edge. But what if you want to use JavaScript to build a backend server, read a file on your computer, or automate a task?

Enter Node.js. Node.js is a powerful, open-source runtime environment that allows you to execute JavaScript code directly on your computer's operating system, entirely outside of a web browser. It revolutionized web development by allowing developers to use a single language (JavaScript) for both frontend and backend development.

Why This Matters

As you progress in your journey to become a Full-Stack Developer, you will need to build APIs, interact with databases, and handle server logic. Node.js is the engine that powers backend frameworks like Express.js and is essential for running modern frontend build tools (like Next.js or Vite). Understanding how to set it up is a mandatory step in modern web development.

Core Concepts

Node.js is NOT a Language

A common misconception is that Node.js is a new programming language or a framework. It is neither. It is simply an environment (a C++ program running the V8 JavaScript engine) that understands and executes JavaScript code.

NPM (Node Package Manager)

When you install Node.js, it automatically installs npm. NPM is the world's largest software registry. It allows you to download and use millions of free code packages (libraries) written by other developers to speed up your own projects.

Syntax

To verify if Node.js is installed correctly, you don't write JavaScript. Instead, you use your computer's Terminal (or Command Prompt).

# Check the installed version of Node.js
node -v

# Check the installed version of npm
npm -v

To run a JavaScript file (e.g., server.js) using Node.js, you use the following command:

node server.js

Real World Example

Let's say you are building the backend for the "Himubey Portfolio" contact form. When a user submits the form, a server needs to receive that data and save it to a database.

Instead of learning Python or PHP to write that server logic, you can use Node.js to write a simple JavaScript file (api.js) that listens for incoming form submissions. You then start that server from your terminal by running node api.js.

Best Practices

  • Use the LTS Version: When downloading Node.js from the official website, always choose the LTS (Long Term Support) version. It is more stable and reliable for production applications compared to the "Current" version which may contain experimental features.
  • Use a Code Editor: To write Node.js scripts efficiently, download a modern code editor like Visual Studio Code (VS Code). It has a built-in terminal that makes running node commands incredibly seamless.

Common Mistakes

Mistake: Trying to use browser-specific objects like window or document inside Node.js. Correction: Because Node.js runs on your operating system and not in a browser, it has no concept of a webpage, DOM, or window. If you try to run document.getElementById() in Node.js, it will throw an error.

💡 Himubey Tip

If you are planning to work on multiple projects that require different versions of Node.js, look into installing NVM (Node Version Manager). It allows you to easily switch between different Node.js versions on your machine with a simple command!

Interview Questions

  1. Is Node.js a programming language? If not, what is it?
  2. What is NPM and why is it installed alongside Node.js?
  3. Name one significant difference between running JavaScript in the browser vs. running it in Node.js.

Mini Challenge

  1. Go to nodejs.org and download the LTS installer for your operating system.
  2. Run the installer and complete the setup.
  3. Open your computer's Terminal or Command Prompt.
  4. Type node -v and press Enter. If you see a version number (like v20.9.0), congratulations, you have successfully installed Node.js!

Summary

Node.js unlocks the full potential of JavaScript by allowing it to run outside the web browser. It is essential for modern backend development and build tools. By installing Node.js, you also gain access to npm, opening the door to a massive ecosystem of developer tools and libraries.

Next Lesson

Variables in JavaScript

Design & Developed by Himanshu Dubey © 2026