Node.js interview questions
Questions often used to check whether a candidate understands how Node handles concurrency and how an Express service is put together.
Most server work is waiting on databases, files or other services, and Node hands that waiting to the operating system and its thread pool. The JavaScript thread only runs short callbacks when results arrive. That is why one blocking loop hurts everyone, and why CPU-heavy work belongs in worker threads or a separate service.
nextTick callbacks run first, right after the current operation, then promise callbacks, both as microtasks. setTimeout callbacks run in the timers phase of the next loop iteration. So for the same tick, the order is nextTick, then promise, then timeout.
Middleware is a function that sits between the incoming request and the final route handler, with access to req, res and next. I use it for parsing bodies, logging, authentication and error handling. Each one must either end the response or call next, and they run in the order registered.
I wrap the awaited work in try/catch and call next(err), or use a small asyncHandler wrapper, so the error reaches one central error middleware. That handler logs the details and sends a safe message with the right status code. On newer Express versions rejected promises are forwarded automatically, but I still keep the central handler.
dependencies are packages the app needs to run, such as Express or a database driver. devDependencies are only for development, like test runners, linters and build tools. A production install can skip devDependencies, which keeps the deployed image smaller.
I read configuration from environment variables, validate them once at startup and fail early if a required one is missing. Locally I use a .env file that is in .gitignore, and in production the values come from the hosting platform's secret settings. Nothing secret goes into the repository or the logs.
Practise out loud. Say each answer once as written, then again in your own words with your own number or story.
Have a number ready. "My Node.js score is at benchmark on a timed test" is a stronger answer than "I am good at it". Take the test and quote the result.
More in Web and app