Node.js Introduction

What Node.js is, V8 and libuv conceptually, installing Node, and your first script.

What Node.js is

Node.js is a runtime that lets JavaScript run outside the browser — on a server, in a CLI tool, or anywhere else you'd otherwise reach for Python, Ruby, or Go. Before Node existed (it was released in 2009 by Ryan Dahl), JavaScript was a browser-only language. Node changed that by taking the same JavaScript engine that powers Google Chrome and giving it access to the filesystem, network sockets, and other operating-system-level capabilities a server needs.

V8 and libuv, conceptually

Node.js is built from two main pieces working together:

  • V8 — Google's open-source JavaScript engine (also what powers Chrome). It's what actually parses and executes your JavaScript code, compiling it to machine code for speed.
  • libuv — a C library that gives Node its event loop and non-blocking I/O capabilities: reading files, making network requests, and talking to databases, all without blocking the single JavaScript thread while waiting for those operations to finish.
Plaintext
Your JavaScript code
        |
        v
     V8 engine  --- executes your JS, manages memory/garbage collection
        |
        v
   libuv (event loop) --- handles I/O (files, network, timers) asynchronously,
                          notifies your JS code via callbacks when operations finish

The practical result: Node.js is famously good at handling many simultaneous connections (like thousands of open HTTP requests) using a single main thread, because it doesn't dedicate one OS thread per connection the way many older server architectures did — instead, it hands off slow I/O work (disk reads, network calls) to libuv, keeps the main thread free to keep handling other work, and comes back to your JavaScript callback only once the I/O operation has actually finished. This model — the event loop, callbacks, promises, and async/await — is covered in depth later in this track.

Installing Node.js

Download an installer from nodejs.org (choose the current LTS — Long Term Support — version unless you have a specific reason not to), or use a version manager like nvm if you need to switch between multiple Node versions on the same machine. Once installed, verify it from a terminal:

Bash
node --version
# v20.11.0

npm (Node's package manager, covered in depth on the next page) ships bundled with Node automatically:

Bash
npm --version
# 10.2.4

Hello, Node

Create a file and run it directly with node — no compilation step, no build tool required for a simple script:

Javascript
// hello.js
console.log('Hello, Node.js!');
Bash
node hello.js
# Hello, Node.js!

Node also has a REPL (Read-Eval-Print Loop) for quick experiments — just run node with no arguments:

Bash
node
> 1 + 1
2
> console.log('interactive!')
interactive!

npm init and package.json

Any real Node project starts with a package.json file — it records the project's name, version, dependencies, and scripts. npm init generates one interactively (or npm init -y to accept all the defaults instantly):

Bash
npm init -y
JSON
{
  "name": "my-node-app",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  }
}

This file is the foundation the rest of this track builds on: it's where dependencies (like Express, covered later) get recorded when you npm install them, and where custom scripts (like npm start or npm run dev) get defined.

Common mistakes

  • Installing a very old Node version (or one so new it's not yet LTS) and hitting compatibility issues with popular packages — sticking to the current LTS release is the safest default for most projects.
  • Running a script with node and being surprised that top-level await or import syntax doesn't work — this depends on the module system in use, covered on the next page.
  • Forgetting that console.log in Node writes to the terminal's standard output, not a browser's DevTools console — a common mental slip for developers coming from front-end-only JavaScript.

Interview questions

Q: What is Node.js, in one sentence? A JavaScript runtime, built on Google's V8 engine plus the libuv library, that lets JavaScript run outside a browser — on a server, in a CLI tool, or anywhere else — with access to the filesystem, network, and other OS-level capabilities browsers deliberately don't expose to JavaScript.

Q: What roles do V8 and libuv each play in Node.js? V8 parses and executes the JavaScript itself, compiling it to machine code. libuv provides the event loop and non-blocking I/O — the mechanism that lets Node handle file access, network requests, and timers asynchronously without blocking the single main JavaScript thread while waiting on them.