Back to results for “Fundamentals”
Node.js › Node.js Fundamentals & Runtime Architecture

What is Node.js, and how does it differ fundamentally from running JavaScript in a web browser?

Beginner

Answer

Node.js is a JavaScript runtime built on Google Chrome's V8 engine, extended with additional APIs (file system access, networking, process management) that let JavaScript run outside the browser as a general-purpose server-side and scripting environment -- unlike a browser, Node.js has no DOM, no 'window' object, and no browser-specific Web APIs, but it does have access to the operating system's file system, native networking sockets, and other server-oriented capabilities browsers deliberately restrict for security reasons.
// This works in Node.js but not in a browser
const fs = require('node:fs');
const data = fs.readFileSync('/etc/hostname', 'utf-8');

// This works in a browser but not in Node.js (no DOM exists)
// document.getElementById('app').innerText = 'Hello';
Real-world example A team building both a web frontend and a backend API in JavaScript can share certain pure business-logic modules (like a pricing calculator with no DOM or filesystem dependency) between the browser-based frontend and the Node.js-based backend, but must keep DOM-manipulation code and filesystem-access code strictly separate since only one runtime supports each.

Common follow-ups: Why can't a typical browser-based JavaScript library that manipulates the DOM be used directly in a Node.js server application?;What specific security sandboxing does a browser apply to JavaScript that Node.js deliberately doesn't, given its different intended use case?