What is Express.js?
Learn what Express.js is: a minimal Node.js web framework for building servers and REST APIs with routing and middleware, plus a simple example.
Expected Interview Answer
Express.js is a minimal, unopinionated web framework for Node.js that simplifies building HTTP servers and REST APIs through routing, middleware, and request/response helpers.
Built on top of Node's http module, Express provides a thin abstraction over raw request handling. It lets you define routes for URL paths and HTTP methods, chain middleware functions that process requests, and send responses with convenience methods like res.json(). It is unopinionated, meaning it imposes little structure and leaves architectural choices to the developer.
- Fast, minimal setup for servers and APIs
- Powerful middleware pipeline
- Simple, expressive routing
- Large ecosystem of compatible packages
- Convenience helpers over the raw http module
AI Mentor Explanation
Express is like the match officials and field markings that turn a bare ground into a playable game — the pitch (Node's http) is just grass until stumps, creases and umpires define where the ball goes and who handles each appeal. Express adds routing and rules on top of raw Node so every incoming delivery reaches the right fielder and gets a clear decision.
Step-by-Step Explanation
Step 1
Install Express
Run npm install express and require it in your entry file.
Step 2
Create an app
Call express() to get an application instance that manages routes and middleware.
Step 3
Define routes
Use app.get, app.post etc. to map a URL path and HTTP method to a handler.
Step 4
Add middleware
Register functions with app.use() to run parsing, auth or logging before handlers.
Step 5
Start listening
Call app.listen(port) to bind the server and accept incoming HTTP connections.
What Interviewer Expects
- Knows Express is a Node.js web framework
- Understands routing and HTTP methods
- Can describe the middleware concept
- Aware it builds on the core http module
- Knows it is minimal and unopinionated
Common Mistakes
- Calling Express a programming language instead of a framework
- Forgetting app.listen so the server never starts
- Confusing Express with Node.js itself
- Not returning or ending a response, leaving requests hanging
- Registering middleware after the route it should protect
Best Answer (HR Friendly)
“Express.js is a popular tool for building web servers and APIs in Node.js. It makes it easy to define web addresses (routes) and to process incoming requests through a series of steps called middleware, so developers can build backends quickly.”
Code Example
const express = require('express');
const app = express();
app.use(express.json());
app.get('/hello', (req, res) => {
res.json({ message: 'Hello from Express!' });
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});Follow-up Questions
- What is middleware in Express.js?
- How does Express routing work?
- How does Express differ from raw Node.js http?
- What does express.json() do?
- How do you handle errors in Express?
MCQ Practice
1. Express.js is best described as?
Express is a minimal, unopinionated web framework that runs on Node.js for building servers and APIs.
2. Which method starts an Express server listening for requests?
app.listen(port) binds the server to a port and begins accepting HTTP connections.
3. Express is built on top of which Node.js core module?
Express is a thin abstraction over Node's built-in http module.
Flash Cards
What is Express.js? — A minimal, unopinionated Node.js web framework for building servers and APIs.
How do you define a route? — Use app.get/post/put/delete with a path and a handler function.
What does app.listen do? — Binds the server to a port and starts accepting HTTP requests.
What is Express built on? — Node.js's core http module, adding routing and middleware helpers.
Send JSON in Express? — Use res.json(data) to serialize and send a JSON response.