Back to Interview Prep
Course progress0/16 chapters · 0%

Chapter 1 of 17

~9 min

Introduction to Node.js

Node.js is a JavaScript runtime that lets you run JavaScript outside the browser, which is what makes it possible to write backend servers, command-line tools, and build scripts in the same language you use on the frontend.

What Node.js Actually Is

Node.js is not a language and not a framework - it is a runtime built on top of the V8 JavaScript engine, the same engine that powers Google Chrome. V8 compiles JavaScript straight to machine code, which is a big part of why Node.js is fast enough to be used for real production servers rather than just browser scripting.

On its own, V8 only understands JavaScript the language - it has no idea what a file system or a network socket is, since those concepts do not exist inside a browser tab. Node.js wraps V8 and adds exactly that: APIs for reading files, opening TCP connections, spawning processes, and more, exposed as built-in modules like `fs`, `net`, and `http`.

libuv and the Non-Blocking Model

Underneath Node.js sits a C++ library called libuv, which provides the event loop and a thread pool for operations the operating system cannot do asynchronously on its own (like some file system calls or DNS lookups). This is what enables Node's signature style: a single main JavaScript thread that never blocks waiting on I/O, instead registering a callback and moving on to the next piece of work.

This model is why Node.js tends to shine at I/O-heavy workloads - APIs, real-time services, proxies - where a server spends most of its time waiting on a database, another service, or a client, rather than crunching numbers on the CPU.

Why Node.js Is Used for Backend, CLI Tools, and Build Tooling

Because a single JavaScript codebase can power both a React frontend and its backend API, teams save real time on tooling, type sharing, and hiring - a JavaScript developer can move between the two with far less context switching than jumping to an entirely different backend language.

Node's module system and the npm registry also make it a natural fit for command-line tools and build tooling: webpack, Vite, ESLint, and the TypeScript compiler are all Node.js programs, distributed as npm packages and run with a single `node` invocation or an npm script.

Running Your First Script

A Node.js program is just a `.js` file executed by the `node` binary from your terminal. There is no HTML page and no `<script>` tag involved - `node` reads the file, runs it top to bottom, and gives the script access to globals like `require`, `module`, and `process` that only exist in the Node.js runtime, not in a browser.

A minimal Node.js script

// hello.js
const os = require('os');

console.log('Hello from Node.js!');
console.log('Node version:', process.version);
console.log('Platform:', os.platform());
console.log('CPU cores:', os.cpus().length);

// Run it from a terminal with:
//   node hello.js

Coding Challenge

Write a small Node.js script that prints the current Node.js version, the current working directory, and how many milliseconds the process has been running, using only built-in globals (no npm packages).

Answer every question below to mark this chapter as complete.

Quiz Yourself

Score: 0/4

1. What is Node.js, precisely?

2. What role does libuv play in Node.js?

3. Why is Node.js particularly well-suited to I/O-heavy workloads?

4. Which of the following is an example of Node.js being used as build tooling rather than a server?

This is a free preview lesson. Sign up to unlock the full course.Sign up freeSign in