JavaScript on the server & APIs.
2 topics
Node.js runs JavaScript on the server using V8 engine. Event loop: single-threaded but non-blocking I/O via libuv. CommonJS (require) vs ES Modules (import). Built-in modules: fs (file system), path, http, crypto, events, stream, buffer, child_process. NPM/pnpm for package management. package.json scripts and workspaces.
2 resources
Express.js or Fastify for HTTP servers. Route handling: GET/POST/PUT/DELETE, path params, query params, request body parsing. Middleware: authentication, validation, error handling, logging, CORS. Structure: controllers, services, repositories. Input validation with Zod or Joi. Response formats and status codes. Rate limiting.
Connect to databases: Prisma (type-safe ORM, migrations, studio), Drizzle (lightweight, SQL-like), or native drivers (pg for PostgreSQL, mongoose for MongoDB). Connection pooling for production. Migrations for schema evolution. Transactions for data integrity. Redis for caching and sessions.
Authentication: JWT (stateless), sessions (stateful), OAuth 2.0 / OIDC, Passport.js, or Auth.js. Testing: Jest or Vitest for unit tests, Supertest for API integration tests. Deployment: Docker containers, PM2 for process management, environment variables, health checks. Performance: clustering, worker threads for CPU tasks, streams for large data.