Event loop, streams, Express, REST APIs, authentication and performance — all covered.
NodeJS is a JavaScript runtime built on Chrome's V8 engine. It allows JavaScript to run on the server side. It uses an event-driven, non-blocking I/O model, making it lightweight and efficient for real-time applications.
The event loop is what allows NodeJS to perform non-blocking I/O operations. It processes callbacks from the callback queue when the call stack is empty. Phases: timers, I/O callbacks, idle, poll, check, close callbacks.
process.nextTick() executes callback before the next event loop iteration, after the current operation completes. setImmediate() executes callback in the check phase of the next event loop iteration.
Streams are objects that allow reading or writing data continuously. Types: Readable, Writable, Duplex (both), Transform (duplex that modifies data). They are memory efficient for handling large files.
Middleware is a function that has access to request, response, and next function. It executes in order, can modify req/res objects, end the request-response cycle, or call next() to pass to the next middleware.
require() is CommonJS module syntax, synchronous, and can be used anywhere. import is ES6 module syntax, asynchronous, and must be at the top level. NodeJS now supports both.
npm (Node Package Manager) is the default package manager for NodeJS. It manages project dependencies, scripts, and publishes packages to the npm registry.
package.json holds metadata about the project including name, version, dependencies, devDependencies, and scripts. It enables npm to install correct dependency versions.
Clustering allows NodeJS to create child processes (workers) that share the same port. Since NodeJS is single-threaded, clustering utilizes multiple CPU cores to handle more requests.
In async code: use try/catch with async/await or .catch() with Promises. For EventEmitter, listen to error event. Use process.on("uncaughtException") as last resort. Always handle errors to prevent crashes.
Sign up free to access complete notes — DSA, System Design, HR and more.
🚀 Access Full Notes Free →