Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 133 ยท Getting Started

Getting Started with Node.js

Learn what Node.js is, what it is used for, and run your first program. Meet Node 24 LTS, ES modules, fetch, the test runner and built-in SQLite.

JavaScript was born inside web browsers, where it made buttons click and menus open. Node.js takes the same language out of the browser and lets it run anywhere: on your laptop, on a server, inside a build tool, in a container. With Node you can read files, talk to databases, answer web requests, write command-line tools and run tests, all in the language you may already know from web pages.

This course teaches the modern Node: version 24 (the current Long-Term Support line), written with ES modules, async/await, the built-in fetch, the built-in test runner and the built-in SQLite module. Every example runs in the editors on this page, so you can change code and see what happens without installing anything. If you have never written JavaScript, skim the JavaScript tutorial first; if you know the basics, you are ready.

What Node.js is

Node.js is a runtime: a program that can read JavaScript text and execute it. It is made of a few big parts:

  • V8, Google's JavaScript engine (the same one inside Chrome). It compiles your JavaScript to machine code and runs it quickly.
  • libuv, a C library that does the waiting for you: files, sockets, timers and the event loop that wakes your code up when something is ready.
  • Node's own libraries, a large standard library (node:fs, node:http, node:crypto, ...) that gives JavaScript the powers a browser never allows, such as reading any file or opening a network port.

The language is the same JavaScript you know. What changes is the world around it: there is no page, no document, no window. Instead you get files, processes, networks and streams. How Node.js works opens up the engine; Node.js vs the browser compares the two worlds side by side.

What people build with it

Node is one of the most widely used runtimes in the world. Typical jobs:

  • Web servers and APIs. Node handles many connections at once without one thread per connection, which suits JSON APIs, chat servers and gateways. See HTTP servers and REST APIs.
  • Command-line tools. Formatters, bundlers, linters, deployment scripts. Much of the web tooling you may use daily is a Node program. See CLI tools.
  • Real-time apps. Chat, live dashboards and notifications over WebSockets or server-sent events.
  • Build and tooling pipelines for front-end projects, and glue scripts that move data between systems.
  • Data processing. Reading large files as streams instead of loading them whole.

Node is not the best choice for everything. Heavy number crunching on one thread (video encoding, big matrix math) is better done in a language built for it, or in a worker thread. The next lesson explains why.

Your first program

A Node program is just a text file of JavaScript. When you run it, Node starts, executes the file from top to bottom, and exits when there is nothing left to wait for. Press Run to try the classic first program.

Node.js Hello from Node.js

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

console.log writes a line of text to the standard output (stdout), which in a terminal is your screen and here is the Output panel. The last two lines show a small but important idea: in Node, document does not exist, while process (information about the running program) does. Code that needs to know where it runs can check for these.

On your own computer you would save the code as hello.mjs and run node hello.mjs in a terminal. Running Node covers that in detail, plus the REPL and the useful flags.

Which version are we using?

Node releases a new major version every six months (April and October). Even-numbered versions become LTS (Long-Term Support) in October and get security fixes for about thirty months, which is what production servers should run. Odd-numbered versions are short-lived "Current" releases. This course targets Node 24 LTS, and it tells you when a feature needs a recent version.

Node.js Check the runtime

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

process.versions lists the version of Node and of each component inside it. The last line shows something you will meet again in ES modules: in our editor your code runs as an ES module, where the old require function does not exist.

On your machine, run node --version in a terminal to see what you have installed. A tool such as nvm, fnm or the official installer lets you keep several versions side by side.

Modern Node comes with batteries included

A few years ago Node was a tiny core plus thousands of packages from npm. Today much of what you would install is already built in. Here is a small tour; each topic gets its own lessons later.

fetch and Web APIs

fetch, URL, AbortController, TextEncoder and many other browser APIs are available as globals. To keep the example self-contained, we start a tiny server on your own machine ("loopback") and call it. Our editor has no outside network, so fetching real websites fails here, but they work normally on your computer.

Node.js fetch talks to a local server

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Notice listen(0, ...): port 0 asks the operating system for any free port, and server.address().port tells us which one. We never print the number because it changes every run. Notice also await at the top level of the file: ES modules allow it, so no wrapper function is needed. server.close() at the end lets the program exit; an open server would keep Node alive forever.

A test runner

node:test lets you write and run tests with no extra install. Testing has a whole chapter; here is the shape.

Node.js A first test with node:test

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The runner prints a report, including how long each test took; those timings differ from run to run, so we never rely on them.

A database

node:sqlite is a complete SQL database inside Node, with no server to install. It was still marked experimental in Node 24, so you may see a warning on stderr, and the API can still change. SQLite in Node goes deep.

Node.js An in-memory SQLite database

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

How this course works

Each lesson explains an idea in plain words, shows it in an editor you can change, and ends with a short quiz. Some points to remember:

  • Examples run on a real Node.js 24 on our server, not simulated. Output you see is what Node prints.
  • No npm packages are installed in the editors. When a lesson talks about Express or other packages, you will see read-only code marked as such, plus a runnable hand-made stand-in.
  • Timings, random values and port numbers change, so the lessons never depend on them.
  • Servers always listen on 127.0.0.1 and are closed at the end, so the program can finish.

Do not just read. Change a value, break something on purpose, read the error message. Error messages in Node are detailed, and learning to read them is half of being productive.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is Node.js?

    Node.js is a runtime built on the V8 engine and libuv. The language is still JavaScript; Node adds files, networking and processes.
  2. 2. Which of these exists in Node but not in a browser page?

    process describes the running Node program. document is browser-only, while console and fetch exist in both.
  3. 3. Which Node.js releases should production servers normally use?

    Even-numbered releases become Long-Term Support in October and receive fixes for about thirty months.
  4. 4. Why does the fetch example call server.close() at the end?

    Node exits when nothing is left to wait for. A listening server is something to wait for, so it must be closed.

Summary

  • Node.js is a runtime that runs JavaScript outside the browser, built from V8, libuv and a large standard library.
  • It is used for web servers, APIs, command-line tools, real-time apps and tooling.
  • This course uses Node 24 LTS and ES modules; fetch, node:test and node:sqlite are built in.
  • In our editors code runs as an ES module with top-level await, and there are no npm packages and no outside network.
  • Programs end when nothing is left to wait for, so close servers and timers.

Next: How Node.js Works