Learn Node.js Roadmap

A structured roadmap to go from JavaScript fundamentals to production-ready Node.js APIs. Covers the event loop, core modules, Express, authentication, databases, testing, and deployment.

study, coding, productivity

by Morris

JavaScript Prerequisites for Node.js

Node.js is just JavaScript on the server. Before diving in, make sure you are comfortable with modern JS - especially async patterns, modules, and destructuring. Skipping this causes endless confusion later.

  • Understand ES modules vs CommonJS (import/export vs require)
  • Master async/await and Promises
  • Learn destructuring, spread/rest, and optional chaining
  • Understand closures and the `this` keyword
  • Practice error handling with try/catch and Promise.catch
  • Get comfortable with array methods: map, filter, reduce, find, some, every

Node.js Internals - Event Loop, libuv, Non-Blocking I/O

Understanding why Node.js is fast for I/O-heavy workloads (and slow for CPU-heavy ones) prevents a whole class of bugs and architectural mistakes.

  • Learn what the event loop is and how it processes callbacks
  • Understand why Node.js is fast for concurrent I/O despite being single-threaded
  • Learn what BLOCKS the event loop and how to avoid it
  • Explore the phases of the event loop: timers, I/O callbacks, poll, check, close
  • Run an experiment: block the event loop with a sync operation and observe the effect
  • Learn about Worker Threads for CPU-intensive tasks

Core Modules

Node.js ships with a rich standard library. These built-in modules cover most needs without installing anything.

  • Learn the `fs` module for file system operations
  • Use the `path` module for cross-platform file paths
  • Build a basic HTTP server with the `http` module
  • Learn the `events` module and EventEmitter pattern
  • Understand Streams for processing large data without loading it all into memory
  • Use the `os` module to inspect the host environment
  • Learn `Buffer` for working with binary data (images, files)

npm and Package Management

npm is the backbone of the Node.js ecosystem. Understanding it deeply prevents dependency hell and security issues.

  • Understand package.json: name, version, scripts, dependencies, devDependencies
  • Learn semantic versioning (semver): major.minor.patch and the ^ ~ prefixes
  • Understand package-lock.json and why it must be committed to version control
  • Learn to use npm scripts for common tasks instead of global CLIs
  • Practice: install, remove, audit, and update packages
  • Set up nodemon for automatic server restarts during development

Building REST APIs with Express.js

Express is the most widely used Node.js web framework. Learning its routing and middleware model unlocks the whole ecosystem.

  • Set up a basic Express app with routes
  • Understand the middleware stack and how next() works
  • Use Express Router to organize routes into separate files
  • Write centralized error handling middleware
  • Handle query parameters, route parameters, and request body
  • Add CORS headers with the cors package
  • Set security headers with the helmet package

REST API Design Principles

Good API design makes your API intuitive to consume and easy to version without breaking clients.

  • Use correct HTTP methods for each operation
  • Return correct HTTP status codes
  • Implement request validation with Zod or Joi
  • Design consistent JSON response shapes
  • Add API versioning via URL prefix (/api/v1/)
  • Implement pagination for list endpoints

Authentication and Authorization

Auth is where most security vulnerabilities live. Learn it carefully.

  • Understand the difference between authentication and authorization
  • Hash passwords with bcrypt before storing them
  • Implement JWT-based authentication
  • Learn the refresh token pattern for long-lived sessions
  • Implement role-based authorization middleware
  • Never expose sensitive data (passwordHash, internal IDs) in API responses

Database Integration

Most Node.js apps need a database. Learn both SQL (with Prisma or pg) and the patterns that prevent SQL injection.

  • Understand the difference between an ORM and a query builder and raw SQL
  • Set up Prisma with PostgreSQL
  • CRITICAL: always use parameterized queries to prevent SQL injection
  • Use Prisma Client to perform CRUD operations
  • Write and run database migrations
  • Handle database connection pooling

Error Handling and Logging

Production apps fail. Good error handling means you know when, why, and how - without leaking sensitive info to clients.

  • Create a custom AppError class for structured errors
  • Add structured logging with Pino
  • Never expose stack traces or internal error details to API clients
  • Handle uncaught exceptions and unhandled promise rejections
  • Add request ID to all log lines for traceability

Testing Node.js Apps

Automated tests catch regressions before they reach production. Learn the two most useful test types for APIs.

  • Set up Jest or Vitest as the test runner
  • Write unit tests for service functions
  • Write integration tests for API routes with supertest
  • Set up a separate test database and reset it between tests
  • Mock external services (email, payment) in tests
  • Measure and track test coverage

Deployment and Production

Getting your API from laptop to server - securely and reliably.

  • Manage secrets with environment variables and dotenv
  • Add a health check endpoint for monitoring
  • Use PM2 to keep the Node.js process alive in production
  • Containerize the app with Docker
  • Set up a reverse proxy with Nginx in front of Node.js
  • Configure graceful shutdown to finish in-flight requests

Capstone Project

Build a complete, production-ready REST API that ties together everything in this roadmap.

  • Design the data model and API contract before writing code
  • Scaffold the project with a clean folder structure
  • Implement full auth flow: register, login, refresh token, logout
  • Build at least two resources with full CRUD and proper authorization
  • Add input validation to every route that accepts a body
  • Write integration tests for the happy path and key error cases
  • Deploy to a cloud provider (Railway, Render, Fly.io, or VPS)