What Node.js is and how it works
Node.js is a runtime for JavaScript outside the browser: the V8 engine executes your code, while the node: modules and the libuv library give it access to files and the network. People use Node.js to write HTTP servers and APIs, network services and command-line tools.
A Node.js application runs in a single process and does not create a thread for each request. While I/O is in progress — reading a file, querying a database or calling over the network — the JavaScript thread does not sit idle but runs the callbacks of other requests. When the operation completes, Node.js returns to its result. That is why one server can hold thousands of concurrent connections without any manual thread handling.
Node.js is strongest where there is a lot of I/O and little computation: HTTP APIs, services with many connections, scripts. Heavy computation in JavaScript occupies the main thread, and while it runs, every other client waits. Split such work into chunks or move it to separate threads — see the “Event loop” section for details.
Node.js is built in layers. Your code calls built-in modules such as node:fs, node:http and node:crypto. The V8 engine executes the JavaScript, and the modules pass system operations through C++ bindings to the libuv library. libuv runs the event loop. It asks the OS to watch sockets and files — epoll on Linux, kqueue on macOS, IOCP on Windows — and calls a callback when an event is ready. Whatever the OS cannot do asynchronously — file operations, dns.lookup(), heavy crypto and zlib functions — is handled by the libuv thread pool (the worker pool).
dns.lookup(), crypto and zlib.How Node.js differs from the browser
| Aspect | Node.js | Browser |
|---|---|---|
| Who chooses the version | you: the server’s Node.js version is known in advance | the visitor: the browser and its version are not known in advance |
DOM: document, window | no | yes |
| Files and network | modules such as node:fs and node:http | only through browser APIs; no file system |
| Modules | ES modules (import) and CommonJS (require()) | ES modules (import) |
| Global objects | globalThis, process, Buffer; require and __dirname only in CommonJS | globalThis, window, document |
| Shared web APIs | fetch, URL, AbortController, TextEncoder, structuredClone | the same |
Code that uses neither the DOM nor node: modules often works in both environments: fetch(), Headers and AbortController in Node.js are compatible with their browser counterparts. The global object in Node.js is globalThis; global is kept for compatibility. A variable declared at the top level of a file stays inside the module and does not become global.
What you need to know first
- JavaScript: functions, objects, promises,
async/await, theimportandexportsyntax — see the JavaScript reference. - The command line: running programs, environment variables — see the Linux and Bash references.
- For servers, HTTP methods, status codes and headers — see the HTTP and REST reference.
Section sources
the section is written from these pages- Introduction to Node.jsnodejs.org/learn/getting-started/introduction-to-nodejs(opens in a new tab)
- Differences between Node.js and the Browsernodejs.org/learn/getting-started/differences-between-nodejs-and-the-browser(opens in a new tab)
- The Node.js Event Loopnodejs.org/learn/asynchronous-work/event-loop-timers-and-nexttick(opens in a new tab)
- Don't Block the Event Loop (or the Worker Pool)nodejs.org/learn/asynchronous-work/dont-block-the-event-loop(opens in a new tab)
- Global objectsnodejs.org/docs/latest-v26.x/api/globals.html(opens in a new tab)