Skip to content

Introduction to Node.js

Node.js lets you run JavaScript outside the browser, on servers, in command-line tools, and inside build pipelines. This introduction explains what Node.js actually is, where it came from, and why it became the default choice for building backend APIs in JavaScript.

What Is Node.js?

Node.js is a JavaScript runtime built on Google's V8 engine, the same engine that powers Chrome. Ryan Dahl created it in 2009 to solve a specific problem: web servers of that era struggled to handle many simultaneous slow connections efficiently, because each connection typically blocked a thread while waiting on I/O.

Node.js pairs V8 with libuv, a C library that provides an event loop and non-blocking I/O. Instead of spawning a thread per connection, a single Node.js process can juggle thousands of open sockets, file reads, and network requests concurrently, moving on to other work instead of waiting.

// hello.js
console.log('Hello from Node.js!');
console.log('Node version:', process.version);

Run this with node hello.js in a terminal. Unlike browser JavaScript, Node.js gives you process, require/import, and direct access to the file system and network, but no window or document.

Running a Node.js File

node hello.js
node --version
node -e "console.log(1 + 1)"
  • node <file>.js executes a JavaScript file with the Node.js runtime.
  • node --version (or node -v) prints the installed Node.js version.
  • node -e "code" runs a one-line script directly from the command line.
  • Node.js scripts have no browser globals like window, document, or alert.

Node.js Quick Facts

Key facts about Node.js worth remembering before you dive into the rest of this course.

Fact Detail
Created by Ryan Dahl, first released in 2009
JavaScript engine V8 (also used by Google Chrome)
I/O model Event-driven, non-blocking, single main thread
Package manager npm (bundled with Node.js), also yarn and pnpm
Common uses REST APIs, CLIs, build tools, real-time servers, scripting
Not used for Rendering a browser UI directly, it has no DOM

Why Node.js Was Created

Before Node.js, most production web servers (Apache with PHP, Java servlet containers) used a thread-per-request model. Every incoming connection consumed a thread, and threads are relatively expensive in memory and context-switching overhead. Under thousands of slow or idle connections, this model wasted resources.

Ryan Dahl's insight was to combine JavaScript, a language with first-class callback support and no built-in blocking I/O APIs, with an event loop. The result could handle huge numbers of concurrent connections on a single thread, because it never blocked waiting for disk or network I/O to complete.

  • Single-threaded event loop instead of one OS thread per connection.
  • Non-blocking I/O throughout the core APIs (files, network, DNS).
  • JavaScript as the language, reusing skills from the front end.
  • npm grew alongside it into the largest package registry in the world.

What You Can Build With Node.js

Node.js is general-purpose, but it particularly shines wherever you need to juggle many I/O-bound tasks at once: talking to databases, calling other APIs, reading files, or handling many simultaneous client connections.

  • REST and GraphQL APIs (often with Express or Fastify).
  • Real-time apps like chat and live dashboards (with WebSockets).
  • Command-line tools and developer tooling (npm itself is written in JS/Node).
  • Build tooling, bundlers, and static site generators.
  • Microservices that talk to databases, queues, and other services.

Common Mistakes

  • Thinking Node.js is a programming language, it's a runtime for executing JavaScript outside the browser.
  • Expecting browser globals like window or document to exist in Node.js scripts.
  • Assuming Node.js is multi-threaded by default; the main JavaScript execution is single-threaded.
  • Confusing Node.js with a specific framework, Express, NestJS, and others all run on top of Node.js.

Key Takeaways

  • Node.js is a JavaScript runtime built on Chrome's V8 engine plus the libuv library.
  • It uses a single-threaded, event-driven, non-blocking I/O model to handle many connections efficiently.
  • It was created by Ryan Dahl in 2009 specifically to solve the concurrent-connection problem.
  • It is commonly used for APIs, CLIs, real-time apps, and developer tooling, not for rendering a browser UI.

Pro Tip

Install Node.js through a version manager like nvm rather than a single global installer. Different projects often require different Node.js versions, and a version manager lets you switch instantly with a single command.