These are the Node.js questions you'll encounter in technical interviews, each with a detailed written answer. Master the event loop and async patterns, then work through streams, APIs, and advanced topics.
40 questions with answersLast updated: Oct 10, 2026
Node.js is a JavaScript runtime built on Chrome's V8 engine. It allows JavaScript to run on servers and has become the foundation of modern backend development, enabling full-stack JavaScript development.
Node.js interviews test your understanding of the event loop, asynchronous programming, streams, file systems, and the npm ecosystem. You'll discuss module systems, middleware, and how to build scalable backend systems.
Node.js expertise is critical for backend and full-stack development. Master the runtime and you'll be ready for roles at startups and enterprises alike.
Reading answers is not the same as giving them. Sit a full mock interview and get scored on how you actually explain them.
How would you describe Node.js and what problems does it solve for backend development?
Answer
Node.js enables writing backend code in JavaScript. Non-blocking I/O handles many concurrent connections efficiently. Single-threaded event loop with async operations scales better than traditional threaded models for I/O-bound tasks.
2Multiple choice
Explain the event loop and how it enables asynchronous operations
Answer
Event loop runs on single thread. Processes call stack first. Then microtasks (Promises). Then macrotasks (setTimeout, I/O). This allows non-blocking operations: async functions pause, returning control to event loop.
3Multiple choice
Explain callbacks and how they handle asynchronous operations in Node.js
Answer
Callback function passed to async operation. Executed when operation completes. Error-first callbacks: callback error, result. Nested callbacks create callback hell. Promises and async/await are modern alternatives.
4Multiple choice
Describe Promises and how they improve over callback-based asynchronous code
Answer
Promise represents eventual value or error. States: pending, resolved, rejected. .then handles success, .catch handles error. Chaining .then calls avoids callback nesting. Promise.all waits for multiple promises.
5Multiple choice
Explain async/await and how it simplifies asynchronous code flow
Answer
async function returns Promise. await pauses function, waits for Promise. Code reads synchronously. try/catch handles errors. More readable than .then chains. Still non-blocking internally.
6Multiple choice
Describe npm and its role in Node.js package management
Answer
npm installs packages from npm registry. package.json lists dependencies. npm install fetches and installs. Semantic versioning: major.minor.patch. npm scripts automate tasks. Enables code reuse across projects.
7Multiple choice
Explain middleware and how it processes requests in Express applications
Answer
Middleware: function receiving request, response, next. Executes code, modifies request/response, calls next() to continue chain. Order matters. Common: logging, authentication, parsing, error handling.
8Multiple choice
Describe REST API principles and how to implement them with Express
Answer
REST: GET retrieve, POST create, PUT update, DELETE remove. Routes: app.get path, callback. Status codes: 200 success, 201 created, 404 not found, 500 error. Express handles routing and responses easily.
9Multiple choice
Explain database connections and connection pooling for performance
Answer
Creating connections is expensive. Connection pool maintains ready-to-use connections. Reusing connections reduces overhead. Pool size affects throughput and resource usage. Configure based on application load.
10Multiple choice
Describe error handling patterns and best practices in Node.js applications
Answer
try/catch wraps async/await. Error middleware in Express: (error, request, response, next) signature. Unhandled errors crash application. Proper handling: log, respond with status code, continue gracefully.
11Written answer
Describe Node.js purpose, how it runs JavaScript outside browsers, and its ecosystem
Answer
Node.js is a runtime built on Chrome's V8 JavaScript engine. Runs JavaScript server-side outside browsers. Single-threaded with non-blocking I/O. Perfect for I/O-bound applications like APIs and real-time apps. Ecosystem: Express for web framework, Socket.io for real-time communication, Mongoose for MongoDB, testing with Jest, build tools with Webpack. npm provides 2+ million packages. JavaScript everywhere: same language frontend and backend.
12Written answer
Explain how the event loop manages synchronous code, callbacks, and microtasks
Answer
Event loop runs on main thread. Phases: execute call stack synchronous code first, then process microtask queue Promises, then macrotask queue setTimeout, I/O, timers. Microtasks run before next macrotask. Understanding phases prevents timing bugs. Blocking operations block entire event loop. Non-blocking operations like file reads return control to event loop immediately.
13Written answer
Explain callback-based asynchronous patterns and callback hell
Answer
Callbacks are functions executed when async operation completes. Node.js uses error-first callbacks: callback error, result. Reading files, database queries, network requests use callbacks. Nested callbacks creating pyramid structure: error handling becomes complex, code readability suffers. Callback hell demonstrates need for Promises and async/await. Modern code prefers Promises and async/await over callbacks.
14Written answer
Describe Promise states, then/catch chains, and Promise.all
Answer
Promises have three states: pending initial, resolved success, rejected error. then handlers success, catch handlers error, finally runs regardless. Chaining thens allows sequential operations. Promise.all waits for all promises, returns array of results, rejects on first error. Promise.race returns first completed promise. Promise.allSettled returns all results with status.
15Written answer
Explain async/await syntax, try/catch error handling, and concurrency patterns
Answer
async keyword makes function return Promise. await pauses function waiting for Promise. Code reads synchronously, executes asynchronously. try block contains await, catch handles rejections. finally runs regardless. Multiple awaits execute sequentially. Using Promise.all awaits multiple promises concurrently. Proper error handling crucial for production reliability.
16Written answer
Describe npm, package.json, dependencies, and version management
Answer
npm is Node.js package manager. package.json defines project metadata, scripts, dependencies, devDependencies. npm install reads package.json, downloads packages from npm registry, creates node_modules folder. Semantic versioning: major.minor.patch. Caret ^ allows minor updates, tilde ~ allows patch updates. package-lock.json locks exact versions for reproducible installs. npm scripts automate tasks like testing and building.
17Written answer
Explain middleware chains, request/response objects, and common middleware
Answer
Middleware functions execute in order. Signature: function middleware request, response, next. Receives request object properties, methods, response object methods for sending data. next() calls next middleware. Middleware can modify request/response. Common: express.json parses JSON, express.static serves files, cors handles cross-origin, authentication checks credentials. Error middleware has four parameters error, request, response, next.
18Written answer
Describe REST principles, routing, status codes, and request/response handling
Answer
REST uses HTTP methods: GET retrieves, POST creates, PUT updates, DELETE removes. Routes define URLs and handlers. Express: app.get path, callback. Status codes: 200 OK, 201 Created, 400 Bad Request, 404 Not Found, 500 Server Error. Request body accessed via request.body after middleware parses. Response sent via response.json, response.send, or response.status. RESTful APIs are stateless, cacheable, and predictable.
19Written answer
Explain connection pooling, query execution, and transaction management
Answer
Database connections are expensive to create. Connection pool maintains ready connections. Applications request from pool, release after use. Pool size affects performance: too small causes waiting, too large wastes resources. Query execution: send SQL or operations to database, receive results. Transactions: group operations, commit all or rollback all. Connection pooling libraries: pg-pool for PostgreSQL, mysql2 for MySQL.
20Written answer
Describe try/catch, error middleware, logging, and graceful error responses
Answer
try block wraps potentially throwing code. catch block handles exceptions. Error object contains message and stack trace. Error middleware in Express: app.use error, request, response, next signature. Middleware runs if error thrown or passed to next. Logging: save error details for debugging, different levels: info, warn, error. Graceful responses: return status code and error message without crashing application.
21Spoken answer
Walk through how you would build a simple REST API with Express
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Answer
I created Express server with app.listen 3000. Defined routes: app.get api users callback returning users array. app.post api users callback reading request.body, validating, creating user, returning status 201. Used middleware: express.json parses JSON. Error handling: try-catch in routes, error middleware catches uncaught errors. This demonstrated REST principles with predictable HTTP methods and status codes.
22Spoken answer
Describe a situation where you debugged an event loop issue
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Answer
Application was blocking event loop. Profiling showed long-running synchronous operation in request handler. Moved computation to worker thread or broke into smaller async chunks. Event loop now responsive to other requests. Learned: keep handlers short, offload heavy work, avoid blocking operations.
23Spoken answer
Explain how you would migrate callback-based code to async/await
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Answer
Legacy code had nested callbacks handling file reads and database queries. Converted to async/await: async function, await on operations, try/catch for errors. Code readability improved dramatically. Error handling centralized in try/catch. Sequential operations now look synchronous.
24Spoken answer
Talk about handling errors in production Node.js applications
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Answer
Production errors crash application if unhandled. I implemented error middleware logging to file and database. Each request wrapped in try/catch. Unhandled rejections caught with process.on uncaughtException. Errors returned as JSON with status 500. Graceful shutdown: application continues serving while restarting. Monitoring alerts on critical errors.
25Spoken answer
Describe implementing middleware for authentication
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Answer
I created authentication middleware verifying tokens from headers. Middleware checked validity, rejected with 401 if invalid, added user info to request if valid. Applied middleware to protected routes: app.use path, authMiddleware, handler. This centralized auth logic, protected routes without duplication.
26Spoken answer
Explain how you would optimize database queries for performance
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Answer
I profiled slow queries using database tools. Added indexes on frequently queried columns. Avoided N+1 queries: batch operations or join queries instead of looping. Used query caching for frequently accessed data. Selected only needed columns instead of wildcard. Result: queries 10x faster.
27Spoken answer
Walk through creating a connection pool for database access
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Answer
I created connection pool with pg-pool: new Pool connectionString, max 10 connections. Application requested connections, executed queries, released connections. Pool reused connections across requests. This reduced connection overhead. Configured pool size based on load testing.
28Spoken answer
Talk about managing async operations with Promise.all
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Answer
API needed to fetch user, posts, and comments concurrently. I used Promise.all userId, postId => Promise.all fetchUser, fetchPosts, fetchComments. All requests ran in parallel. Result returned array with all data. Much faster than sequential awaits.
29Spoken answer
Describe testing Node.js API endpoints
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Answer
I used Jest and supertest to test API. Test created request: request app .get api users .expect 200. Mocked database. Verified response structure. Tested error cases: missing fields, invalid input, 404 responses. Continuous integration ran tests on push. 100% coverage on critical paths.
30Spoken answer
Explain how you would deploy a Node.js application to production
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Answer
I built Docker image with Node.js runtime, packaged application. Pushed image to registry. Deployed to cloud platform: AWS ECS, Google Cloud Run, or Heroku. Environment variables configured per deployment. Monitoring with application performance monitoring tools. Logs aggregated to central service. Graceful shutdown handled in process.on SIGTERM.
31Coding
Create a basic Express server with a GET route returning JSON
Build your Node.js solution here
Answer
const express require express; const app express; app.get api hello (request, response) => { response.json { message Hello World } }; app.listen 3000, () => console.log Server running );
32Coding
Build a POST route that accepts JSON data and returns a response
Build your Node.js solution here
Answer
app.post api users (request, response) => { const user request.body; if not user.name return response.status 400 .json error; response.status 201 .json { id 1, ...user } };
33Coding
Write an async function fetching data and handling errors with try/catch
Build your Node.js solution here
Answer
async function fetchData() { try { const data await fetch url .then res => res.json; return data; } catch error { console.error error; } }