Setting Up Node.js and npm for Beginners

Node.js lets JavaScript run outside the browser — on your own computer, powering backend servers and command-line tools. This guide covers installing it and confirming everything works.

If you’ve worked through our guides on package managers and JavaScript basics, Node.js is the natural next step — the environment that lets JavaScript step beyond the browser entirely.

What Node.js Actually Is

According to freeCodeCamp’s beginner’s guide to Node.js, Node is an environment that lets you run JavaScript code outside the web browser, using Google’s V8 engine to convert JavaScript into machine code the same way Chrome does internally — just without a browser wrapped around it.

Since Node runs outside a browser, it doesn’t have access to browser-only features like the DOM or window — but it gains access to things browsers intentionally restrict, like reading and writing files directly on your computer.

Installing Node.js

According to npm’s official installation documentation, the most common way to get Node.js and npm is downloading the installer directly from nodejs.org, which bundles npm automatically — no separate installation step needed.

  1. Go to nodejs.org and download the LTS (Long-Term Support) version — the stable, recommended choice for most users, especially beginners.
  2. Run the installer and follow the prompts, keeping the default settings.
  3. Restart your terminal (or computer, on Windows) once installation finishes.

Verifying the Installation

node --version
npm --version

Seeing version numbers for both confirms Node.js and npm installed correctly — the same verification pattern covered in our Python installation guide, just for a different language’s runtime.

Running Your First Node.js Script

console.log("Hello, world!");

Save this as hello.js, then run it from your terminal:

node hello.js

This is the same JavaScript syntax covered throughout our JavaScript Basics series — Node.js runs it identically to a browser console, just without any HTML page or DOM involved.

Starting a New Node.js Project

mkdir my-node-project
cd my-node-project
npm init -y

This creates a basic package.json file, described in more depth in our package manager guide — the metadata file every npm project relies on to track its dependencies.

Managing Multiple Node Versions

As your projects grow, you may eventually need different Node.js versions for different projects. A tool called NVM (Node Version Manager) handles this cleanly, letting you switch versions with a single command rather than reinstalling Node repeatedly. As a beginner, this isn’t necessary right away — plain LTS installed directly is enough until you have a specific reason to need multiple versions side by side.

Using Node’s Built-In Modules

Beyond running plain JavaScript, Node.js ships with built-in modules for common tasks — no separate installation required. The fs (file system) module lets you read and write files directly from JavaScript:

const fs = require("fs");
fs.writeFileSync("notes.txt", "Hello from Node!");
const content = fs.readFileSync("notes.txt", "utf8");
console.log(content);

This mirrors the file handling concepts covered in our Python files guide — different language, same underlying idea of reading and writing persistent data, just using JavaScript syntax and Node’s specific API instead.

Installing on Different Operating Systems

According to GeeksforGeeks’ installation guide, Windows users download and run the .msi installer, working through a standard setup wizard, while macOS users use the equivalent .pkg installer — both bundling npm automatically as part of the same install. Linux users commonly install through their distribution’s package manager instead, or via NodeSource’s setup scripts for a more current version than what’s typically available in default repositories.

Global vs. Local npm Packages

As covered in more depth in our package manager guide, packages installed with npm can be local (specific to one project) or global (available system-wide, typically for command-line tools). A common beginner mistake is installing packages that should be local dependencies globally instead, which can cause version mismatches between different projects that need different versions of the same tool.

Common Questions

Do I need Node.js if I’m only building websites with plain HTML/CSS/JS? Not necessarily for the frontend itself, but many modern frontend tools (build tools, package managers, frameworks) run on Node.js behind the scenes, so it’s worth having installed even for frontend-focused work.

What’s the difference between the “Current” and “LTS” versions? LTS prioritizes stability with a longer support window — the safer default for beginners and most projects. “Current” includes the newest features but changes more frequently and is better suited to experimenting with cutting-edge capabilities.

Quick-Reference Guide

  • Node.js — runs JavaScript outside the browser, using the V8 engine.
  • nodejs.org — official download source; choose the LTS version.
  • node –version / npm –version — confirms successful installation.
  • node filename.js — runs a JavaScript file with Node.
  • npm init -y — creates a package.json for a new project.

Conclusion

Installing Node.js takes just a few minutes and opens up an entire category of JavaScript work — command-line tools, backend servers, and the build tools behind most modern frontend frameworks. With Node and npm both covered, you have the full toolkit needed to take JavaScript beyond the browser.

In the next guide in this series, we’ll cover the difference between an IDE and a text editor, rounding out the tooling concepts covered throughout this series.

Explore More Tools & Setup Guides →

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top