Node.js runtime
Syllabus
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.