Chapter 1 of 18 · Node.js for Beginners — Complete Free Tutorial

Introduction to Node.js

Welcome to the Node.js for Beginners tutorial series on Scriptly. Across 18 chapters you will go from your first node hello.js to a deployed REST API — covering modules, npm, asynchronous code, files, HTTP, Express and production basics. This first chapter answers the opening questions: what Node.js is, how it differs from browser JavaScript, and what actually happens when you run a script.

What is Node.js?

Node.js is a JavaScript runtime: a program that takes your JavaScript, compiles it with Google's V8 engine and runs it on a machine instead of inside a browser tab. It adds what browsers never give you — access to the file system, network sockets, processes and the operating system — while keeping the language, syntax and core patterns you already know.

  • Not a language and not a framework — JavaScript is the language; Node.js is one environment that executes it, just as Chrome is another.
  • One command to run — the node executable plus a built-in standard library of modules you can require with no install step.
  • Cross-platform — the same script runs on macOS, Linux and Windows without changes in the vast majority of cases.

Browser JavaScript vs Node JavaScript

The language transfers completely; the environment changes completely. This table lists the differences you will feel from day one.

ConcernIn the browserIn Node.js
Entry point<script> tag or module importnode file.js
Global objectwindowglobalThis, plus process
Main APIsDOM, events, fetch, alertfs, path, http, streams, child processes
SecuritySandboxed — no arbitrary file or port accessFull machine access — never run untrusted code
Typical jobInteractivity inside a pageServers, APIs, command-line tools, automation

What ships inside Node

  • V8 — parses and runs your JavaScript, JIT-compiling hot paths for near-native speed.
  • libuv — the C layer providing the event loop, timers, and non-blocking file and network I/O backed by a thread pool.
  • The standard library — built-in modules such as fs for files, path for paths, http for servers and os for system details.
  • npm — the package manager and public registry that installs alongside Node (chapter 5).

Your first Node program

Confirm the runtime is installed — any current LTS release works for this series:

node --version

Expected output:

v24.6.0

Now save a small file and run it. No HTML, no browser, no dev tools window:

// hello.js
const name = 'Asha';
console.log(`Hello from ${name}!`);
console.log('Running on Node', process.version);
node hello.js

Expected output:

Hello from Asha!
Running on Node v24.6.0

Notice the global object process: it describes the running program — version, arguments, environment and lifecycle. There is no document and no window in Node; their practical replacements are process, the standard library and the modules you write yourself.

The event loop in ten lines

Node runs your code on a single JavaScript thread, but it never idles: work that would block (disk, sockets) is handed to the system, and finished work returns as callbacks on the event loop. The classic proof:

console.log('1: synchronous');

setTimeout(() => console.log('3: after the timer'), 0);

console.log('2: still synchronous');

Expected output:

1: synchronous
2: still synchronous
3: after the timer

Synchronous lines run in order; the timer callback waits in a queue until the stack is empty. One thread plus many in-flight requests is why a small Node process can serve thousands of connections — chapter 6 unpacks the whole model.

What Node is built for

  • REST APIs and microservices — the bread and butter; chapters 12 to 18 build one end to end.
  • Command-line tools — programs that read arguments and files: linters, scaffolding scripts, Git clients.
  • Real-time services — chat, live dashboards and collaborative apps on WebSockets.
  • Build tooling — bundlers, transpilers, test runners and task runners are mostly Node programs.
  • Serverless functions — short-lived Node handlers invoked per request on cloud platforms.

Common mistakes

  • Expecting a DOM — document, window and alert do not exist in Node; they throw ReferenceError.
  • Running untrusted code — Node has full machine access, so evaluating user input as code is remote code execution.
  • Confusing runtime with package manager — Node runs code; npm installs packages. They ship together but are separate tools.
  • Installing an outdated version — stick to an active LTS release so examples and security fixes match.
  • Blocking the single thread — heavy synchronous work stalls every request; that is a recurring theme from chapter 6 onward.

Practice checklist

  1. Run node --version and npm --version in your terminal and note both outputs.
  2. Create hello.js that prints your name, today's date and process.version.
  3. Predict the output of the timer example before running it, then verify.
  4. Write down three apps you use daily that could be powered by Node and why.

You now know what Node is — the next step is getting a current version installed and meeting the REPL. Next: Installing Node.js and Using the REPL.

Quiz: Introduction to Node.js

5 questions · 70% to pass

Frequently Asked Questions

Node.js is a runtime that executes JavaScript outside the browser. It combines Google's V8 engine with APIs for files, networks, processes and streams, plus a package ecosystem (npm). You use it to build servers, command-line tools, APIs and anything that needs JavaScript running on a machine rather than in a page.

JavaScript is the language; Node.js is one environment that runs it. In the browser the language comes with a DOM, events and window APIs — in Node those are replaced by the file system, network and process modules. Syntax, functions, arrays, promises and async/await are identical, so your JavaScript knowledge transfers directly.

Browser code is sandboxed: it cannot read your files or open arbitrary ports. Node code has full machine access, which is why it is used for servers and tools but also why you never run untrusted code in it. There is no document or window in Node — the equivalents are global, process and modules.

npm is JavaScript's package manager and public registry. package.json describes your project: name, entry point, dependencies with version ranges, and scripts such as npm run dev. Installing a package copies it into node_modules and records the exact intent in package-lock.json so every machine installs identical versions.

Express is a minimal web framework for Node: a few thousand lines that give you routing, middleware, request parsing and static files on top of the raw HTTP server. It is the most common starting point for REST APIs and the backbone of this tutorial's project chapters.

Both work. CommonJS (require/module.exports) is the classic Node format; ES modules (import/export) are the standard and activated in a package.json with "type": "module". Modern projects favour ESM for browser compatibility, but you will read both in existing code, so this course teaches each.

Middleware are functions that run between the incoming request and the final response, in order: body parsing, logging, authentication, rate limits, error handling. Each receives the request, response and next function and can respond itself or pass control along — Express's pipeline model in one sentence.

A JSON file is perfect for learning CRUD: no setup, readable data, easy to reset. The moment you need concurrent writes, querying or multiple users, move to a real database — MySQL/PostgreSQL for relational data or MongoDB for documents. The storage chapter isolates persistence behind one module so swapping it later is straightforward.

A REST API exposes resources over HTTP using verbs on URLs: GET /api/todos lists, POST creates, PUT or PATCH updates, DELETE removes, and everything answers with JSON plus correct status codes (200, 201, 400, 404, 500). It is stateless — each request carries its own authentication — which makes it easy to cache, scale and consume from any frontend.

Node apps are long-running processes, not static files: deploy them to a Node-friendly host (a VPS, Render, Railway or Fly.io), keep secrets in environment variables, terminate HTTPS at a reverse proxy or platform edge, and send logs somewhere durable. The final chapter covers the full checklist including health checks and graceful shutdown.