All questions
Showing of 52How do you create a basic Express.js application?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Create an application by calling express(), register a route on it, and start the server with app.listen(). Install the package first with npm install express.
const express = require('express');
const app = express();
const PORT = 3000;
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
app.get('/', ...) registers a route handler that runs for GET requests to the root path, and res.send() writes the response. The server listens on port 3000 and answers the root route with Hello World!. Express answers every other path with 404 Not Found. app.listen() returns the Node.js http.Server it creates, which you keep when you need to close the server later.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is middleware in Express.js?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Middleware is a function that runs during the request-response cycle. It has access to the request object req, the response object res, and the next function. Express passes each request through a chain of these functions, in the order you register them.
A middleware function can:
- run any code, such as logging or timing
- change
reqorres, for example by addingreq.user - end the cycle by sending a response
- call
next()to hand control to the next function in the chain
// Custom middleware
app.use((req, res, next) => {
console.log('Time:', Date.now());
next(); // Call next to continue to the next middleware
});
This one logs a timestamp for every request and then calls next(), so the routes still run. A middleware that neither responds nor calls next() leaves the request hanging.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are the different types of middleware in Express.js?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
The Express docs list five types of middleware.
- Application-level middleware is bound to the app object with
app.use(). - Router-level middleware works the same way, but is bound to an
express.Router()instance withrouter.use(). - Error-handling middleware takes four arguments,
(err, req, res, next). - Built-in middleware ships with Express, such as
express.staticandexpress.json. - Third-party middleware comes from npm packages, such as
morgan,corsandhelmet.
The types overlap. Third-party cors() mounted with router.use() is also router-level middleware, and an error handler can sit on the app or on a router.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you handle different HTTP methods in Express.js?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Express has one routing method per HTTP method, named after it in lowercase, such as app.get(), app.post() and app.delete(). Each takes a path and a handler, and the handler runs only when both the method and the path match.
app.get('/users', (req, res) => {
res.send('GET request');
});
app.post('/users', (req, res) => {
res.send('POST request');
});
app.put('/users/:id', (req, res) => {
res.send('PUT request');
});
app.delete('/users/:id', (req, res) => {
res.send('DELETE request');
});
Here /users answers GET and POST with different handlers, and /users/:id answers PUT and DELETE for one user. A method that no route handles, such as PATCH on /users, falls through to the 404 response. app.get() also answers HEAD requests for the same path.
To keep every method of one path together, chain them with app.route(), such as app.route('/users').get(...).post(...). Use app.all() when one handler must run for every method.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the purpose of next() function in middleware?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
next() passes control to the next middleware or route handler in the chain. A middleware that does not send a response must call it, or the request is left hanging.
app.use((req, res, next) => {
if (req.headers.authorization) {
next(); // Continue to next middleware
} else {
next(new Error('Unauthorized')); // Trigger error handling
}
});
next has three common forms:
next()moves on to the next matching function.next(err)skips the normal functions and jumps to the error-handling middleware.next('route')skips the remaining callbacks of the current route and moves to the next matching route.
Use return next() when more code follows, so the function stops there.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you serve static files in Express.js?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Use the built-in express.static middleware and point it at a folder. Express then maps request paths to files in that folder, such as images, CSS and JavaScript.
// Serve files from 'public' directory
app.use(express.static('public'));
// Serve with virtual path prefix
app.use('/static', express.static('public'));
With the first line, public/logo.png is served at /logo.png, because the folder name is not part of the URL. The second line adds a virtual path prefix, so the same file is also at /static/logo.png. The folder path is relative to where you start the node process, so path.join(__dirname, 'public') is safer.
When no file matches, the middleware calls next(), so later routes still run. In Express 5, it ignores dotfiles such as .env by default. For high traffic, put a reverse proxy cache in front of the static files.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the difference between req.params, req.query, and req.body?
How do you enable CORS in Express.js?
What is Express Router and why use it?
What is Express.js and why is it used?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Express.js is a minimal web framework for Node.js. It adds routing, middleware and response helpers on top of Node's built-in http module.
With plain http, one callback parses the URL, reads the body stream and sets headers such as Content-Type itself. Express gives you routes such as app.get('/users/:id', handler), a middleware chain for shared steps such as authentication, and helpers such as res.json().
Teams use it for REST APIs and server-rendered sites. Its small core is quick to learn, and middleware packages add most other features. It is unopinionated, so it does not pick a folder structure, a validation library or a database for you. Express 5 is the current major version and needs Node.js 18 or later.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you handle 404 errors in Express.js?
What is the difference between res.send(), res.json() and res.end()?
What are template engines and how does Express use them?
What is the purpose of body-parser middleware?
How do you implement error handling in Express.js?
What is the difference between app.use() and app.get()?
How do you implement authentication middleware?
How do you handle file uploads in Express.js?
What are Express.js route parameters and how do you validate them?
How do you implement rate limiting in Express.js?
How do you implement session management in Express.js?
What is the difference between cookies and sessions?
How do you implement logging in Express.js?
How do you handle environment variables in Express.js?
What is Express.js middleware execution order?
How do you implement data validation in Express.js?
What is the difference between app.all() and app.use()?
How do you implement request ID tracking across middleware?
What changed between Express 4 and Express 5?
How would you implement role-based access control in Express.js?
How would you structure a large Express.js application?
What is the difference between app.locals and res.locals in Express?
How do you implement request/response compression in Express.js?
How do you implement API documentation with Express.js?
How do you implement security headers in Express.js?
How do you implement health checks and monitoring?
How do you implement content negotiation in Express.js?
How do you implement request/response transformation middleware?
How do you implement testing strategies for Express.js applications?
How do you implement custom middleware for API versioning?
How do you implement graceful shutdown in Express.js?
How do you implement clustering in Express.js for better performance?
How do you implement caching strategies in Express.js?
How do you implement WebSocket support with Express.js?
How do you implement database connection pooling with Express.js?
How do you implement request timeout handling?
How do you implement custom error classes and error handling strategies?
How do you implement database transactions with Express.js?
How do you implement API rate limiting with different strategies?
How do you implement microservices communication with Express.js?
How do you implement performance monitoring and profiling?
When would you choose Express over NestJS or Fastify?
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
Express.js in pictures.
A quick recap of Express.js in 32 short animated pictures, one idea at a time. About 8 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.
Pro The first chapter is free to play. The other 29 pictures come with Pro.
Express.js cheatsheet
- Apps & routes01
- Middleware & its order02
- Errors & 404s03
- Responses & pages04
- Parse & validate input05
- Login, roles & sessions06
- CORS, headers & rate limits07
- Caching & databases08
- Run it in production09
- Structure, tests & services10
- The model11
- + 5 more inside
This picture is part of Pro. The first chapter is free to play; the other 29 pictures come with Pro.
Get Pro · $10/mo Already Pro? Sign in45 of 52 Express.js answers are in Pro.
Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.
- Full answers + code
- AI explanations, simpler or deeper
- 1,000 AI credits / month
- Cancel anytime
Change topic
Pick a different technology or stack. Your current topic stays put until you choose a new one.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.