Backend

Node.js

A server-side JavaScript runtime built on the V8 engine with an event-driven, non-blocking I/O model.

What it is

Node.js runs JavaScript outside the browser. Under the hood sits Chrome's V8 engine and the libuv library, which handles networking, files and timers through an event loop.

Your code runs on one thread, but I/O does not block it: while one request waits for the database, the event loop serves others. For heavy computation there are worker_threads and separate processes.

The npm ecosystem is the largest of any language. That made Node.js the base for APIs, BFFs, build tools (Vite, webpack) and server-side rendering.

Use it when

  • I/O-heavy services: REST and GraphQL APIs, chats, streaming, websockets.
  • The team already writes JavaScript or TypeScript and wants one language on front and back.
  • You need build tooling, CLI utilities or a BFF for a frontend.

Avoid it when

  • Long CPU-bound jobs (video processing, ML) on the main thread: they block the event loop.
  • You need strict static typing without extra tooling: use TypeScript or another language.

Key concepts

Event loop
A loop that takes ready callbacks from queues and runs them one at a time on the main thread.
libuv
The C library for async I/O and the thread pool underneath Node.
Streams
Processing data in chunks without loading the whole file into memory.
npm / ESM
The package manager and the modern import/export module system.

Example

A minimal HTTP server with no dependencies.

Cheat sheet

Node.js cheat sheet
Command or codeWhat it does
node app.jsRuns a file
node --watch app.jsRestarts on file changes
node --env-file=.env app.jsLoads variables from .env
npm init -yCreates package.json
npm install expressInstalls a dependency
process.env.PORTEnvironment variable
import { readFile } from 'node:fs/promises'Files through the Promise API
await readFile('a.json', 'utf8')Reads a file as text
node --testRuns the built in tests
import path from 'node:path'Working with paths

How to learn it

  1. First take the JavaScript course, especially async and modules.
  2. Take the Node.js essentials course on ShortLesson.
  3. Learn modules, the file system, paths and environment variables.
  4. Understand the event loop and the difference between callbacks, Promises and async/await.
  5. Write an HTTP server, first with the built in http module, then with Express.
  6. Connect a database and build a REST API with authentication.
  7. Add tests with node:test or Vitest.
  8. Use TypeScript in Node and deploy a service.

Interview questions

  1. 1. What is the event loop?

    It is the mechanism that takes finished async operations from queues and runs their callbacks on one thread. It lets Node serve thousands of connections without a thread per connection.

  2. 2. Why should you not block the main thread?

    While synchronous code runs, the event loop is stuck and every other request waits. Heavy computation moves to worker threads or a separate service.

  3. 3. How does process.nextTick differ from setImmediate?

    nextTick runs right after the current operation, before the loop moves on, while setImmediate runs in the check phase after I/O. Too many nextTick calls can starve the loop.

Interview questions from the bank

Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).