Courses / Node.js: From First Script to Production / Chapter 2
Module 2 · Node.js basics · Chapter 2 of 27
Getting Started: What Node.js Is and Running Your First Script
No prerequisites. Next up: Globals and Modules: process, CommonJS and ES Modules.
Part 1 · What Node.js is
A runtime, not a language
A live cricket score page keeps thousands of browsers connected and sends each one a new line every few seconds. Node.js was built for that kind of work: many open connections, each one mostly waiting.
JavaScript is a language. It defines values, functions, objects and promises, and it says nothing about files, network sockets or the screen. Something has to run the language and add those abilities. That something is a runtime. A browser is one runtime: it adds the page (the DOM), fetch and cookies. Node.js is another runtime, one that runs JavaScript outside the browser and adds access to the machine it runs on.
So when you write Node code you use the same language you know from the browser, with different built-in tools. There is no document in Node because there is no page. In its place you get node:fs for files, node:http for servers, node:crypto for hashing and a few dozen more modules that ship inside the program.
Node is open source and runs on Windows, macOS and Linux. It also installs npm, the package manager you will meet in a later chapter, which is how most Node projects get third-party code.