PrepPilotPractise free

Node.js Runtime interview questions

Event loop, streams, workers, memory, performance

17 questions · node · updated November 2026

Practise these as flashcards. One or two lines each; the ones you miss come back first.

Start free

Core questions

What are the main phases of the Node.js event loop?

The main phases are timers, pending callbacks, idle/prepare, poll, check, and close callbacks. Each phase processes specific types of events, such as timer callbacks or I/O events.

How can you block the Node.js event loop?

The event loop is blocked by long-running synchronous code, like heavy computations or infinite loops. This prevents other events from being processed and can make the application unresponsive.

What is back-pressure in Node.js streams?

Back-pressure is a mechanism that prevents writable streams from being overwhelmed by pausing the readable stream when the writable stream can't keep up. It helps manage memory and ensures efficient data flow.

How do you handle environment configuration in Node.js?

I use environment variables, often with the dotenv package, to load configuration from a .env file. This keeps settings separate from code and allows secure management of secrets.

Intermediate questions

How does the libuv thread pool relate to the event loop?

The libuv thread pool handles expensive asynchronous operations, like file system or crypto tasks, outside the main event loop. This allows Node.js to remain non-blocking and responsive even when performing heavy I/O.

How can you detect if your Node.js app is blocking the event loop?

I use profiling tools like clinic.js or node --prof to measure event loop latency. Monitoring response times and using process._getActiveRequests() can also help identify blocking code.

What are the differences between worker threads, clusters, and child processes?

Worker threads run JavaScript in multiple threads and share memory, clusters spawn multiple Node.js processes for scaling servers, and child processes execute external scripts. Each is suited for different concurrency and isolation needs.

How do you prevent memory leaks in Node.js?

I avoid retaining unnecessary references, use weak references when appropriate, and regularly profile memory usage. Heap snapshots taken with Chrome DevTools or node --inspect help identify leaks.

What is the purpose of package-lock.json in npm?

package-lock.json locks dependency versions, ensuring consistent installs across environments. It prevents accidental upgrades and helps with reproducible builds.

How do you handle unhandled promise rejections?

I use process.on('unhandledRejection', handler) to log and handle rejections globally. In production, I prefer to fail fast or shut down gracefully if critical errors occur.

How do you implement graceful shutdown in a Node.js server?

I listen for termination signals like SIGTERM or SIGINT, stop accepting new connections, finish ongoing requests, and close resources like database connections before exiting.

How do you audit your npm dependencies for vulnerabilities?

I run npm audit regularly to check for known vulnerabilities and update affected packages. For critical projects, I use additional tools like Snyk or npm's audit CI integration.

Senior questions

Describe how you would debug a memory leak in a production Node.js app.

See the answer in the app, free

How would you design a Node.js service to handle CPU-bound tasks without blocking requests?

See the answer in the app, free

What are the trade-offs between using worker threads and clusters in Node.js?

See the answer in the app, free

How do you ensure supply-chain security for Node.js applications?

See the answer in the app, free

How would you securely manage secrets in a Node.js application deployed to production?

See the answer in the app, free

More JavaScript & Node.js topics