Node.js Fundamentals Flashcards
Node Architecture & Event Loop Modules (CommonJS, ES Modules) Process & Buffer File System & Streams Error Handling (68 cards)
What is the Node.js architecture?
Node.js uses a single-threaded event loop architecture with non-blocking I/O operations to handle concurrent client requests.
What is the event loop in Node.js?
The event loop in Node.js is the mechanism that handles asynchronous operations by executing non-blocking I/O operations on a single thread.
Advantages of Node.js event loop architecture?
Improved performance for I/O-heavy tasks, high concurrency, low memory consumption, fast handling of numerous simultaneous requests.
Disadvantages of Node.js event loop architecture?
Can be inefficient for CPU-heavy tasks, may lead to blocking of the event loop if not properly managed.
Best practices for Node.js event loop?
Offload CPU-intensive tasks to worker threads, use asynchronous I/O, avoid blocking the event loop.
Use cases for Node.js event loop?
Real-time applications (chat, games), microservices, API backends, streaming services.
Impact of Node.js event loop on system design?
It enables high throughput and scalability, but requires careful management of blocking operations to avoid bottlenecks.
Architectural implications of Node.js event loop?
Allows building highly scalable systems, but requires balancing CPU-heavy tasks and offloading them to avoid event loop blockages.
Performance implications of Node.js event loop?
Good for handling high volumes of I/O-bound requests, but less suited for CPU-heavy tasks which might slow down other requests.
Fault tolerance in Node.js event loop?
Single-threaded architecture makes it susceptible to errors affecting the whole application. Use clustering and worker threads for fault tolerance.
Monitoring and debugging Node.js event loop?
Use tools like Node.js built-in profiler, clinic.js
, or node-inspect
to monitor event loop performance and detect potential bottlenecks.
Common interview question about the event loop?
Explain the event loop in Node.js and how it handles concurrency.
Potential gotchas with Node.js event loop?
Blocking the event loop with synchronous code or unoptimized CPU-heavy tasks can degrade performance and cause unresponsiveness.
What is CommonJS in Node.js?
CommonJS is the module system used in Node.js, allowing you to export and import modules using module.exports
and require()
.
What is ES Modules in Node.js?
ES Modules is the standard JavaScript module system that uses import
and export
syntax, introduced for modern JavaScript.
Advantages of CommonJS?
Works synchronously and is widely supported in Node.js, simple to use with require()
and module.exports
.
Advantages of ES Modules?
Supports import
/export
syntax, allows static analysis and tree shaking, and is the official module system for JavaScript.
Disadvantages of CommonJS?
Synchronous loading, can lead to issues when working with asynchronous code or in browser environments.
Disadvantages of ES Modules?
Not supported natively in all Node.js versions until recently, has potential compatibility issues with CommonJS modules.
Best practices for using modules in Node.js?
Use ES Modules for new projects where possible, use CommonJS for compatibility, prefer named exports over default exports.
Use cases for CommonJS?
Widely used in Node.js for server-side applications, packages, and libraries.
Use cases for ES Modules?
Client-side JavaScript, modern Node.js apps, projects using tree shaking and bundling tools.
Architectural implications of using CommonJS?
CommonJS allows dynamic module loading, but can cause issues with synchronous imports in larger applications.
Performance implications of using ES Modules?
ES Modules enable better optimization, like tree shaking, for bundling and reduce the overall app size.