What is Node.js?
Node.js is a runtime that executes JavaScript outside the browser. A runtime supplies an engine to evaluate code and interfaces for interacting with its host environment. You can use Node.js to build command-line tools, automate work and run backend services. JavaScript is the language; Node.js is one environment in which that language runs.
Local practice: The proposed teaching runtime is Node.js 26.13.1 LTS. These original offline examples were executed on Node.js 22.16.0 (Linux x64); execution on the proposed baseline and in ByteMind is not yet verified. No npm dependencies are required. Use a fresh practice directory. Code blocks are static, not a browser-based Node runner.
Print a bookstore greeting
In the directory containing the files above, run:
node main.mjsExpected standard output:
Welcome to the bookstoreExpected exit status: 0.
How it works
The browser and Node.js both implement JavaScript. They offer different host features: a browser provides the page document and user interface, whereas Node supplies interfaces for processes, files and network services. Some interfaces, such as URL and console, exist in both. The V8 engine executes JavaScript; Node also includes facilities that coordinate work with the operating system. You do not need a web server to run a simple Node script. A terminal is a text interface through which you can ask the operating system to launch Node.
Compare host features
In the directory containing the files above, run:
node main.mjsExpected standard output:
undefinedobjectExpected exit status: 0.
Common mistake
Do not assume every JavaScript API exists in every runtime. In a plain Node process, the browser document is absent. Conversely, an ordinary browser page cannot import arbitrary Node filesystem modules. A package or framework can provide additional interfaces, but that is a separate dependency.
Try it yourself
Change the greeting to name a fictional library. Run the program again. Then predict whether document and console are available in a regular browser page. Explain which difference comes from the host rather than the language.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
What is Node.js? — knowledge check
Check your understanding of what is node.js?.
Which description best fits Node.js?
Why does `typeof document` print undefined in plain Node?
Which task can a Node script perform without a web server?