JavaScript is a programming language. Node.js is a runtime environment that lets you run JavaScript outside the browser, mainly on servers. JavaScript - A language standardised as ECMAScript (ES2015/ES6 and yearly updates since). - Originally designed to run in web browsers to make pages interactive. - In the browser, JavaScript has access to browser APIs: the DOM (document), window, fetch, localStorage, events and Web Workers. - Executed by browser engines: V8 (Chrome, Edge), SpiderMonkey (Firefox), JavaScriptCore (Safari). Node.js - Created in 2009 by Ryan Dahl. It combines Google's V8 JavaScript engine with libuv (an event loop and asynchronous I/O library) and a set of built-in modules. - Provides server-side APIs that browsers do not have: file system (fs), networking (http, net), processes (child_process), streams, crypto, operating system information. - Does not have browser APIs such as document or window. - Uses npm (and alternatives like pnpm or yarn) for packages — the largest package ecosystem in the world. What you can build with Node.js - REST and GraphQL APIs (Express, Fastify, NestJS), real-time applications with WebSockets (Socket.IO), command-line tools, build tools (Vite, webpack and many frontend tooling chains run on Node.js), serverless functions and microservices. Example // Browser JavaScript document.querySelector('#greet').addEventListener('click', () => alert('Hello')); // Node.js import http from 'node:http'; http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ message: 'Hello from Node.js' })); }).listen(3000); Node.js execution model - Single-threaded event loop with non-blocking I/O: while waiting for a database or network response, Node.js serves other requests. This makes it efficient for I/O-heavy workloads such as APIs and chat servers. - CPU-intensive work blocks the event loop, so it should be moved to worker threads or other services. Module systems - Node.js supports CommonJS (require, module.exports) and ES modules (import, export). Modern projects prefer ES modules. Alternatives - Deno and Bun are newer JavaScript runtimes with built-in TypeScript support and different tooling, but Node.js remains the most widely used. Recent Node.js versions can also run many TypeScript files directly by stripping types. Summary table in words - What it is: JavaScript is a language; Node.js is a runtime. - Where it runs: JavaScript runs anywhere an engine exists (browsers, Node.js, Deno, Bun); Node.js runs on servers and developer machines. - APIs available: browser JavaScript has the DOM and web APIs; Node.js has file system, networking and process APIs. - Typical use: browser JavaScript for interactive UIs; Node.js for backends, tooling and scripts. Interview summary: "JavaScript is the language; Node.js is a V8-based runtime with an event loop and server-side APIs that lets JavaScript run on servers, enabling full-stack JavaScript development."
Ravindra Wadile · · 0 likes