Web Frameworks in Node.js


Web Frameworks in Node.js Interview with follow-up questions

1. What are some of the popular web frameworks available in Node.js and how do they differ?

The frameworks interviewers expect you to compare in 2026:

  • Express — the long-standing, minimal, middleware-based standard; huge ecosystem. Express 5 is now released (native promise/async error handling, updated routing). Great default for REST APIs.
  • Fastify — the modern performance-focused choice: very fast, schema-based validation/serialization (JSON Schema), first-class TypeScript, and a plugin/encapsulation system. Increasingly the go-to for new high-throughput services.
  • NestJS — an opinionated, structured framework (TypeScript, DI, modules, decorators — Angular-like) for large, maintainable apps; runs on Express or Fastify under the hood.
  • Koa — minimal and modern (async/await middleware) from the Express team; you assemble everything yourself.
  • Hapi — configuration-driven, batteries-included (validation, auth); less popular now.

How they differ: philosophy (minimal/unopinionated like Express/Koa vs structured like Nest), performance (Fastify leads), built-ins (validation, DI, serialization), and TypeScript ergonomics.

The framing that lands: Express for familiarity and ecosystem, Fastify for performance + schema validation, NestJS for large structured teams. Also worth noting: modern Node ships native fetch, a test runner, and --watch, so some lightweight services skip a framework entirely.

↑ Back to top

Follow-up 1

Can you explain how Express.js simplifies routing and middleware?

Express.js simplifies routing and middleware by providing a clean and intuitive API for defining routes and middleware functions.

  • Routing: Express.js allows developers to define routes using the app.get(), app.post(), app.put(), and app.delete() methods. These methods take a URL pattern and a callback function as parameters. The callback function is executed when a request matches the specified URL pattern. Express.js also supports route parameters, query parameters, and route handlers for handling different types of requests.

  • Middleware: Middleware functions in Express.js are functions that have access to the request and response objects and can modify them or perform additional operations before passing them to the next middleware function in the chain. Express.js provides a app.use() method to register middleware functions. Middleware functions can be used for tasks such as logging, authentication, error handling, and more. They can be chained together to create a pipeline of middleware functions that are executed in the order they are defined.

Follow-up 2

What are some of the key features of Meteor.js?

Some of the key features of Meteor.js are:

  • Full-stack JavaScript: Meteor.js allows developers to write both the client-side and server-side code in JavaScript, making it a full-stack JavaScript framework. This enables code reuse and simplifies the development process.

  • Real-time updates: Meteor.js provides built-in support for real-time updates, allowing data changes on the server to be automatically propagated to connected clients in real-time. This makes it easy to build real-time collaborative applications such as chat apps, collaborative editing tools, and more.

  • Data synchronization: Meteor.js provides a data synchronization layer called 'Meteor Collections' that allows developers to synchronize data between the client and server effortlessly. Changes made on the client are automatically synchronized with the server and vice versa.

  • Hot code reloading: Meteor.js supports hot code reloading, which means that changes made to the code are automatically applied without requiring a page refresh. This significantly speeds up the development process.

  • Package ecosystem: Meteor.js has a rich package ecosystem with thousands of community-contributed packages that can be easily integrated into applications. These packages provide additional functionality and make it easy to extend the capabilities of Meteor.js applications.

Follow-up 3

How does the choice of web framework impact the performance of a Node.js application?

The choice of web framework can have a significant impact on the performance of a Node.js application. Some factors to consider are:

  • Overhead: Different web frameworks have different levels of overhead. Some frameworks may introduce additional layers of abstraction and processing, which can impact the performance of the application. It is important to choose a framework that strikes a balance between ease of development and performance.

  • Caching and optimization: Some web frameworks provide built-in caching and optimization features that can improve the performance of the application. These features can help reduce the number of database queries, optimize network requests, and improve overall response times.

  • Scalability: The scalability of a web framework can also impact the performance of a Node.js application. Some frameworks are designed to handle high levels of concurrency and can scale horizontally to handle increased traffic. Choosing a framework that is scalable can ensure that the application performs well under heavy load.

  • Middleware and plugins: The availability of middleware and plugins can also impact the performance of a Node.js application. Some frameworks have a rich ecosystem of middleware and plugins that can enhance the functionality of the application. However, it is important to choose lightweight and well-optimized middleware to avoid performance bottlenecks.

Overall, the choice of web framework should be based on the specific requirements of the application and the trade-offs between ease of development and performance.

2. How does middleware work in Node.js web frameworks?

Middleware is a function that sits in the request–response pipeline and runs in order for each request. In Express it receives (req, res, next): it can read/modify req/res, do work (auth, logging, parsing), then either call next() to pass control to the next middleware or end the cycle by sending a response.

app.use((req, res, next) => {
  req.startTime = Date.now();
  next();                        // pass to the next middleware/handler
});

Key points interviewers probe:

  • Order matters — middleware runs in registration order; forgetting next() (without responding) hangs the request.
  • Types — application-level, router-level, error-handling (Express error middleware has the special 4-arg signature (err, req, res, next)), and built-in/third-party (express.json(), cors, helmet, morgan).
  • Framework differences — Koa/Fastify use an async, onion-model pipeline (await next()), so you can run code before and after downstream handlers; Express 5 now propagates errors from async middleware automatically.

It's the core extensibility mechanism: cross-cutting concerns (auth, validation, logging, error handling) live in composable middleware instead of being repeated in every route.

↑ Back to top

Follow-up 1

Can you provide an example of a custom middleware function in Express.js?

Sure! Here's an example of a custom middleware function in Express.js:

const express = require('express');
const app = express();

// Custom middleware function
const logger = (req, res, next) => {
  console.log(`[${new Date().toISOString()}] ${req.method} ${req.url}`);
  next();
};

app.use(logger);

app.get('/', (req, res) => {
  res.send('Hello, World!');
});

app.listen(3000, () => {
  console.log('Server started on port 3000');
});

In this example, the logger middleware function logs the current date, request method, and URL to the console before passing control to the next middleware or route handler.

Follow-up 2

What is the role of middleware in error handling in Node.js web frameworks?

Middleware plays a crucial role in error handling in Node.js web frameworks. By placing error-handling middleware after the route handlers, any errors that occur during the processing of a request can be caught and handled appropriately. Error-handling middleware functions have four parameters (err, req, res, next) and are defined with the app.use method. They can be used to log the error, send an error response to the client, or perform any other necessary error handling tasks.

Follow-up 3

How can middleware be used for authentication in a Node.js application?

Middleware can be used for authentication in a Node.js application by intercepting incoming requests and verifying the user's credentials or access token. Here's an example of how middleware can be used for authentication in Express.js:

const express = require('express');
const app = express();

// Authentication middleware
const authenticate = (req, res, next) => {
  const { token } = req.headers;
  if (token === 'secret_token') {
    next(); // User is authenticated
  } else {
    res.status(401).send('Unauthorized');
  }
};

app.use(authenticate);

app.get('/', (req, res) => {
  res.send('Authenticated route');
});

app.listen(3000, () => {
  console.log('Server started on port 3000');
});

In this example, the authenticate middleware function checks if the token header is set to a specific value. If the token is valid, the middleware calls next() to pass control to the next middleware or route handler. Otherwise, it sends a 401 Unauthorized response to the client.

3. What are the advantages of using a web framework like Express.js in Node.js?

Using Express (vs hand-rolling everything on the core http module) gives you:

  1. Routing — a clean API for mapping HTTP methods + paths to handlers, with params, query parsing, and routers for modular organization.
  2. Middleware pipeline — composable handling of cross-cutting concerns (auth, logging, body parsing, CORS, error handling).
  3. Less boilerplate — helpers like res.json(), res.status(), res.redirect(), static-file serving, and template-engine integration.
  4. Huge ecosystem — a vast library of compatible middleware and a massive community, so most problems have a ready solution.
  5. Flexibility — unopinionated, so you structure the app your way and integrate any DB/tooling.

The current, balanced note worth adding: Express 5 modernizes it with built-in async error propagation and updated routing. That said, alternatives trade some of Express's simplicity for other wins — Fastify for raw performance and built-in schema validation/serialization, NestJS for structure and DI on large teams. So the honest answer is "Express buys you speed of development and ecosystem; pick Fastify/Nest when you need performance or structure."

↑ Back to top

Follow-up 1

How does Express.js handle routing?

Express.js handles routing through its routing system. Developers can define routes using the app.METHOD(path, handler) syntax, where METHOD is the HTTP method (e.g., GET, POST, PUT, DELETE) and path is the URL pattern. The handler function is called when a request matching the specified method and path is received.

For example, to handle a GET request to the root URL, you can define a route like this:

app.get('/', function(req, res) {
    res.send('Hello, World!');
});

Express.js also supports route parameters, which allow you to capture parts of the URL and use them in your handler function. Route parameters are denoted by a colon (:) followed by the parameter name.

For example, to handle a GET request to /users/:id, you can define a route like this:

app.get('/users/:id', function(req, res) {
    var userId = req.params.id;
    // Do something with the user ID
    res.send('User ID: ' + userId);
});

Follow-up 2

What are some of the built-in middleware functions in Express.js?

Express.js provides several built-in middleware functions that can be used to add functionality to the application's request-response cycle. Some of the commonly used built-in middleware functions include:

  1. express.json(): This middleware function parses JSON data sent in the request body and makes it available in req.body.

  2. express.urlencoded(): This middleware function parses URL-encoded data sent in the request body and makes it available in req.body.

  3. express.static(): This middleware function serves static files from a directory or multiple directories.

  4. express.Router(): This middleware function allows you to create modular, mountable route handlers.

  5. express.cookieParser(): This middleware function parses cookies sent in the request and makes them available in req.cookies.

These are just a few examples, and Express.js provides many more built-in middleware functions that can be used to enhance the functionality of your application.

Follow-up 3

How can Express.js be used with other libraries and tools like body-parser and cookie-parser?

Express.js can be easily used with other libraries and tools like body-parser and cookie-parser by installing them as dependencies and then requiring and using them in your Express.js application.

For example, to use body-parser to parse JSON and URL-encoded data, you can install it using npm:

npm install body-parser

Then, require and use it in your Express.js application like this:

var express = require('express');
var bodyParser = require('body-parser');

var app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

Similarly, you can use cookie-parser to parse cookies sent in the request. Install it using npm:

npm install cookie-parser

Then, require and use it in your Express.js application like this:

var express = require('express');
var cookieParser = require('cookie-parser');

var app = express();

app.use(cookieParser());

By using these libraries and tools with Express.js, you can enhance the functionality of your application and handle common tasks more easily.

4. How does Meteor.js differ from other Node.js web frameworks?

Meteor is a full-stack, all-in-one JavaScript platform, which sets it apart from libraries like Express that only handle the server. Its distinguishing traits:

  • Integrated stack — bundles client, server, build tooling, and (traditionally) MongoDB into one cohesive system, rather than you wiring pieces together.
  • Real-time data by default — its reactive data layer (publications/subscriptions, historically DDP + Minimongo) automatically syncs data between server and clients, so UIs update live without you writing socket plumbing.
  • Isomorphic JavaScript — the same code/language runs on client and server.
  • Integrated accounts/build — built-in auth packages and hot code push.

Where it differs from the typical Node approach: Express/Fastify are minimal and unopinionated — you choose your DB, real-time layer, and front end. Meteor is opinionated and batteries-included, optimizing for rapid real-time app development at the cost of flexibility and ecosystem lock-in.

The honest 2026 context: Meteor still exists (and has modernized to work with React/Vue and other databases), but it's a niche choice now — most teams assemble their own stack (e.g. Fastify/Nest + a real-time layer like WebSockets/Socket.IO). Expect interviewers to value that you can articulate the integrated vs assemble-your-own trade-off.

↑ Back to top

Follow-up 1

What are the key features of Meteor.js that make it suitable for real-time applications?

Meteor.js is designed to handle real-time applications with ease. Some of its key features include:

  1. Reactive Data: Meteor.js uses a reactive data system that automatically updates the user interface whenever the underlying data changes.

  2. Full-stack Integration: Meteor.js allows developers to write both the client and server code in JavaScript, providing a seamless integration between the front-end and back-end.

  3. Live Data Updates: Meteor.js provides real-time data synchronization between the client and server, allowing instant updates to be pushed to connected clients.

  4. Hot Code Push: Meteor.js supports hot code push, which means that updates to the application can be deployed without requiring the users to refresh their browsers.

These features make Meteor.js a powerful framework for building real-time applications.

Follow-up 2

How does Meteor.js handle data synchronization between client and server?

Meteor.js uses a technique called Distributed Data Protocol (DDP) to handle data synchronization between the client and server. DDP is a lightweight protocol that allows real-time communication between the client and server over a WebSocket connection. When a client subscribes to a data source on the server, any changes made to that data source are automatically propagated to the client in real-time. This allows the client's user interface to be updated instantly whenever the underlying data changes. Meteor.js also provides a set of APIs and abstractions that make it easy for developers to work with data and handle data synchronization.

Follow-up 3

Can you explain how Meteor.js supports full-stack development?

Meteor.js is a full-stack JavaScript framework, which means that it allows developers to write both the client and server code in JavaScript. This provides a seamless integration between the front-end and back-end of the application. The same code can be shared between the client and server, reducing duplication and making it easier to maintain and update the application. Meteor.js also provides a set of APIs and abstractions that make it easy to work with databases, handle data synchronization, and build reactive user interfaces. Additionally, Meteor.js includes a built-in build system and package manager, which simplifies the deployment and management of the application.

5. Can you explain how routing works in Node.js web frameworks?

Routing maps an incoming request's HTTP method + URL path to the handler that should produce the response. The framework inspects each request, finds the matching route, and invokes its handler (running any middleware along the way).

app.get('/users/:id', (req, res) => {
  res.json({ id: req.params.id });   // :id is a route parameter
});
app.post('/users', createUser);

Concepts interviewers expect: route parameters (:idreq.params), query strings (req.query), wildcards/patterns, route order/specificity (more specific routes first; a catch-all 404 last), and grouping related routes with a Router for modularity. Handlers are typically async and should handle errors (Express 5 forwards async errors to error middleware automatically).

A current note: frameworks differ in style — Express/Fastify use programmatic route definitions, Fastify adds per-route JSON-schema validation, and NestJS uses decorators (@Get(), @Post()). The underlying idea is the same: declarative method+path → handler mapping, which is the backbone of building RESTful APIs.

↑ Back to top

Follow-up 1

How does Express.js handle dynamic routing?

Express.js, a popular Node.js web framework, handles dynamic routing by using route parameters. Route parameters are named URL segments that are used to capture the values specified at their position in the URL. These parameters are defined in the route path using a colon followed by the parameter name. For example, a route path of '/users/:id' would match '/users/123' and capture the value '123' as the 'id' parameter. The captured values can then be accessed in the handler function using the 'req.params' object.

Follow-up 2

What is the role of route parameters in Express.js?

Route parameters in Express.js play a crucial role in handling dynamic routes. They allow developers to define routes that can handle variable values in the URL. Route parameters are useful when building APIs or applications that require dynamic data retrieval or manipulation. They provide a way to extract specific values from the URL and use them in the handler function to perform actions based on the captured values.

Follow-up 3

Can you provide an example of a complex route in Express.js?

Sure! Here's an example of a complex route in Express.js:

app.get('/users/:id/posts/:postId', (req, res) => {
    const userId = req.params.id;
    const postId = req.params.postId;
    // Retrieve user and post data based on the captured values
    // Perform actions using the data
    // Send the response
});

In this example, the route path '/users/:id/posts/:postId' captures two route parameters: 'id' and 'postId'. These parameters can be accessed in the handler function using 'req.params'. Developers can then use these captured values to retrieve user and post data, perform actions, and send the appropriate response.

Live mock interview

Mock interview: Web Frameworks in Node.js

Intermediate ~5 min Your own free AI key

Your voice and your AI key never touch our servers; the key stays in this browser and is sent only to Google. Only your round scores are saved to track progress.