Node.js
Core Concepts
What is Node.js and how is it different from browser JavaScript?
Node.js is a JavaScript runtime built on Chrome's V8 engine that allows you to run JavaScript on the server.
| Feature | Browser JS | Node.js |
|---|---|---|
| DOM access | ✅ Yes | ❌ No |
| File system | ❌ No | ✅ Yes |
window object | ✅ Yes | ❌ No (global instead) |
| Modules | ES Modules | CommonJS + ES Modules |
| APIs | Web APIs (fetch, DOM) | Node APIs (fs, http, path) |
Use cases: Web servers, APIs, CLI tools, build tools, real-time apps.
What problems does this solve?
- Establishes the fundamental architectural understanding of asynchronous server environments.
- Prevents critical thread-blocking logic in high-concurrency microservices.
- Highlights the exact mechanism required for scaling real-time web applications.
What is the Event Loop?
The mechanism that allows Node.js to perform non-blocking I/O despite being single-threaded.
The event loop continuously cycles through these phases.
What problems does this solve?
- Exposes the capacity to debug catastrophic memory leaks in production servers.
- Demonstrates understanding of precisely how garbage collection thresholds function.
- Proves safely how to monitor and maintain long-running daemon stability.
What is the difference between process.nextTick() and setImmediate()?
process.nextTick(): Executes immediately after the current operation, before the event loop continues. (Microtask queue)setImmediate(): Executes in the next iteration of the event loop, in the "check" phase. (Macrotask queue)
What problems does this solve?
- Validates the exact approach to handling massive unbuffered data streams efficiently.
- Demonstrates knowledge of piping standard I/O to avoid exceeding V8 heap limits.
- Highlights the ability to safely process gigabyte-scale files without crashing.
What is the difference between Blocking and Non-Blocking?
- Blocking: Execution waits for the operation to complete before moving on.
- Non-Blocking: Execution continues immediately; result is handled via callback/promise.
Rule: Never use blocking methods in production servers.
What problems does this solve?
- Evaluates how cleanly candidates manage secure cryptographic hashing natively.
- Reveals the understanding of how strictly password salting and timing attacks are mitigated.
- Demonstrates safely the proper use of the built-in crypto module over outdated packages.
What is the global object in Node.js?
The equivalent of window in browsers. It contains globally available objects and functions.
What problems does this solve?
- Highlights the exact capacity to properly utilize child processes for CPU-bound tasks.
- Proves cleanly how efficiently a candidate offloads heavy computation safely.
- Demonstrates safely preventing the main event loop from entirely freezing.
What is the process object?
Provides information and control over the current Node.js process.
What problems does this solve?
- Reveals exactly how deep an understanding of libuv thread pools extends.
- Demonstrates safely modifying thread pool sizes to handle massive disk I/O bottlenecks.
- Highlights securely the underlying C++ mechanisms enabling Node.js async operations.
Modules & Package Management
What is the difference between CommonJS and ES Modules?
| Feature | CommonJS | ES Modules |
|---|---|---|
| Syntax | require() / module.exports | import / export |
| Loading | Synchronous | Asynchronous |
| Default in Node | Yes (< v12) | Yes (with .mjs or "type": "module") |
| Top-level await | ❌ No | ✅ Yes |
| Tree shaking | ❌ No | ✅ Yes |
What problems does this solve?
- Evaluates exactly how smoothly candidates build modular ecosystem packages.
- Demonstrates securely the deep understanding of CommonJS versus ES Modules interoperability.
- Highlights completely explicit file scoping for strict state management safely.
How does require() work internally?
- Resolving: Find the file path
- Loading: Read the file content
- Wrapping: Wrap in a function to provide module scope
- Evaluating: Execute the module code
- Caching: Store in
require.cachefor future calls
Caching: Modules are cached after first load. Same require() returns cached result.
What problems does this solve?
- Enables developers to execute a function immediately after the current operation completes, entirely bypassing the slower macro-task queue.
What is the purpose of package.json?
The manifest file for a Node.js project.
What problems does this solve?
- Explains the microscopic prioritization differences within the Event Loop phases, crucial for fine-tuning backend event scheduling.
What is the difference between dependencies and devDependencies?
dependencies: Required to run the app in production.devDependencies: Only needed during development (testing, building, linting).
What problems does this solve?
- Provides the foundational observer pattern architecture that handles continuous, flowing data without overwhelming system memory.
What is package-lock.json?
Records the exact version of every installed dependency (and their dependencies).
Purpose:
- Ensures consistent installs across machines
- Faster installs (skips version resolution)
- Security auditing
Best practice: Always commit package-lock.json to version control.
What problems does this solve?
- Reveals precisely the deep correct understanding purely of strictly the EventEmitter pattern.
- Demonstrates perfectly the ability safely to decouple highly scalable logic entirely.
- Highlights properly preventing completely silent explicit totally explicit memory leaks exclusively.
Asynchronous Patterns
What are Callbacks and what is "Callback Hell"?
Callbacks are functions passed as arguments to be called when an operation completes.
Callback Hell: Deeply nested callbacks that are hard to read and maintain.
Solutions: Promises, async/await, modularizing code.
What problems does this solve?
- Differentiates the exact system-level methods for launching sub-processes, executing shell commands, or spinning up connected Node instances.
How do Promises work?
Promises represent the eventual result of an async operation.
States: Pending → Fulfilled (resolved) or Rejected
What problems does this solve?
- Allows the primary master process to communicate cleanly and bidirectionally with spawned worker threads across restricted memory boundaries.
What is async/await?
Syntactic sugar over Promises for cleaner async code.
What problems does this solve?
- Ensures large binary payloads do not synchronously block the event loop while being transmitted from the network into local storage.
What is util.promisify()?
Converts callback-based functions to Promise-based ones.
Modern alternative: Most Node.js APIs now have .promises versions:
What problems does this solve?
- Demonstrates the drastic memory optimization differences between loading an entire file into RAM versus streaming it in tiny chunks.
File System & Streams
What are Streams and why use them?
Streams handle data piece by piece (chunks) instead of loading everything into memory.
Types:
- Readable: Read data (fs.createReadStream, http request)
- Writable: Write data (fs.createWriteStream, http response)
- Duplex: Both read and write (TCP socket)
- Transform: Modify data as it passes through (zlib, crypto)
What problems does this solve?
- Explicitly protects the API gateway while permitting trusted frontend applications hosted on different domains to request data over HTTP.
How do you pipe streams?
Connecting a readable stream to a writable stream.
Modern syntax (pipeline):
What problems does this solve?
- Provides the modular, plug-and-play request interception architecture that forms the backbone of the entire Express ecosystem.
What is a Buffer?
A fixed-size chunk of memory for handling binary data.
What problems does this solve?
- Ensures unexpected exceptions safely degrade rather than crashing the entire Node process, preventing complete deployment downtime.
How do you handle file uploads?
Using multer middleware with Express:
What problems does this solve?
- Clarifies the difference between broad, catch-all request interceptors and granular, verb-specific endpoint handlers.
HTTP & Web Servers
How do you create an HTTP server in Node.js?
Native:
With Express:
What problems does this solve?
- Demonstrates the horizontal and vertical architectural strategies required to push a single-threaded runtime into a massive concurrent environment.
What is Middleware in Express?
Functions that have access to request, response, and next(). They execute in order.
What problems does this solve?
- Allows a raw Node application to explicitly fork itself and fully utilize multi-core server hardware natively without external orchestrators.
How do you handle CORS in Node.js?
Cross-Origin Resource Sharing allows/restricts cross-origin requests.
What problems does this solve?
- Provides true, CPU-bound multi-threading capabilities directly inside Node to handle math-heavy operations without blocking I/O.
What is the difference between req.params, req.query, and req.body?
What problems does this solve?
- Crucially distinguishes the exact transportation mechanisms for URL path variables, URL query strings, and secure encrypted request payloads during API data parsing.
Security & Best Practices
How do you handle environment variables?
.env file:
Best practices:
- Never commit
.envto version control - Use different files per environment (.env.development, .env.production)
- Validate required variables at startup
What problems does this solve?
- Completely isolates highly fragile infrastructure secrets (like database strings and API keys) externally away from the committed source code.
What security best practices should you follow?
- Validate input (Joi, Zod, express-validator)
- Use Helmet (security headers)
- Rate limiting
- Parameterized queries (prevent SQL injection)
- HTTPS everywhere
- Keep dependencies updated (
npm audit)
What problems does this solve?
- Enforces raw systemic hardening at the gateway level, preventing the most common automated vulnerabilities like DDoS and XSS.
How do you handle errors in Express?
Sync errors: Automatically caught
Async errors: Need try/catch or wrapper
What problems does this solve?
- Surgically sanitizes all incoming dynamic payload data, entirely neutralizing attempts to blindly execute malicious database commands.
Database & ORMs
How do you connect to MongoDB?
With Mongoose:
What problems does this solve?
- Provides stateless, cryptographically-signed authorization tokens, allowing the API to verify users rapidly without a database lookup.
How do you handle database transactions?
MongoDB (Mongoose):
PostgreSQL (Prisma):
What problems does this solve?
- Evaluates the ability to strictly manage closures, event listeners, and garbage collection to prevent the server from eventually crashing with OOM.
Performance & Scaling
How do you scale a Node.js application?
Vertical scaling: Use all CPU cores
Better: Use PM2
Horizontal scaling:
- Load balancer (nginx, HAProxy)
- Container orchestration (Kubernetes)
- Stateless design (no in-memory sessions)
What problems does this solve?
- Demonstrates proficiency with systemic inspecting tools and profiling software to diagnose complex logic bugs running in a remote container.
What is Worker Threads and when do you use them?
Run CPU-intensive JavaScript in parallel threads (not just I/O).
Use cases: Image processing, video encoding, heavy computations, data parsing.
What problems does this solve?
- Ensures the application architecture remains continuously verifiable through comprehensive automated end-to-end and mock integration pipelines.