cchakri.aiLearn All courses
// COURSE · BACKEND

Backend with Node.js

From the Node runtime and HTTP APIs to persistence, authentication, testing, and deployment.

01

Node.js runtime

Syllabus

  1. 01Node, V8, and the event loop
  2. 02Modules, packages, and project layout
  3. 03HTTP server and request lifecycle

Detailed content

Node, V8, and the event loop

Node.js runs JavaScript outside the browser using the V8 engine and operating-system APIs. The event loop coordinates callbacks and asynchronous work; it does not make CPU-heavy JavaScript parallel. Keep request handlers non-blocking, move expensive computation to workers or separate services, and understand how long tasks delay every request on the same loop.

Modules, packages, and project layout

Modules define boundaries for reusable code; package manifests declare scripts and dependencies. Organize code by responsibility, keep configuration explicit, and pin dependency versions through a lockfile. Avoid circular module dependencies. Validate required environment variables at startup so a misconfigured service fails clearly instead of later during a request.

HTTP server and request lifecycle

An HTTP server receives a request, parses its method, path, headers, and body, then returns a status, headers, and response body. Middleware can handle cross-cutting work such as logging or authentication. Set body-size limits, validate content types, and ensure every code path completes with a response or a controlled error.

02

API design and application structure

Syllabus

  1. 01REST routes and resource design
  2. 02Validation and error handling
  3. 03Layering and dependency boundaries

Detailed content

REST routes and resource design

Design endpoints around resources and their lifecycle. Use HTTP methods consistently, choose status codes that describe the outcome, and keep response shapes predictable. Pagination prevents large unbounded results. Version contracts deliberately and document required fields, authorization rules, and error formats so client teams can integrate without guessing.

Validation and error handling

Treat request data as untrusted. Parse it into a validated shape before business logic runs, and reject invalid data with actionable but safe messages. Centralize error translation so internal exceptions do not leak stack traces or secrets. Log enough context to debug failures while excluding credentials and sensitive personal data.

Layering and dependency boundaries

Keep routing, business rules, and persistence concerns separate enough to test independently. A route translates HTTP into an application call; a service enforces domain rules; a repository performs data access. Injecting dependencies makes external systems replaceable in tests without creating abstractions that add no practical value.

03

Persistence and asynchronous work

Syllabus

  1. 01Database access and transactions
  2. 02Authentication and authorization
  3. 03Queues, jobs, and webhooks

Detailed content

Database access and transactions

Use parameterized queries or safe data-access libraries to avoid injection. A transaction groups related writes so invariants are not left half-applied. Decide which errors are retryable and make write operations idempotent when clients may resend a request. Keep database connections pooled and close them cleanly during shutdown.

Authentication and authorization

Authentication establishes who is making a request; authorization checks whether that identity may perform the action on the specific resource. Verify tokens or sessions using trusted libraries, protect cookies, and apply access checks close to the operation. Never rely on a client-side hidden button as a security boundary.

Queues, jobs, and webhooks

Background jobs handle work that should not hold an HTTP request open. Persist job state, limit retries, use exponential backoff, and make handlers safe when a message is delivered twice. Webhooks need signature verification, replay protection, and acknowledgment rules. Expose status so clients can understand delayed work.

04

Security, testing, and operations

Syllabus

  1. 01Security and abuse protection
  2. 02Testing services and APIs
  3. 03Deployment and observability

Detailed content

Security and abuse protection

Use TLS, strict input validation, secure secret storage, and least-privilege credentials. Apply rate limits to expensive or sensitive routes and set request-size and timeout limits. Configure cross-origin access intentionally. Patch dependencies and record security events without logging passwords, tokens, or full payment details.

Testing services and APIs

Test domain rules directly, then test HTTP and database boundaries at integration level. Use realistic but isolated test data. Verify authentication, authorization, validation, and failure behavior, not just successful responses. Keep tests deterministic by controlling time, randomness, external service behavior, and cleanup.

Deployment and observability

Build a repeatable release artifact and run migrations with a rollback or compatibility plan. Health endpoints should distinguish readiness from basic process liveness. Record structured logs, request metrics, error rates, and traces. Graceful shutdown stops accepting new work, finishes in-flight requests within a deadline, and releases connections.