Controller
ELI5 — The Vibe Check
A controller is the manager who actually handles your request after it passes through security. It figures out what data you need, asks the model to fetch it, and sends back the response. It's the brain that coordinates everything.
Real Talk
A controller is a function or class that handles the business logic for a specific route or group of routes. It processes the incoming request, interacts with models or services to get/manipulate data, and returns the appropriate response.
Show Me The Code
const getUserById = async (req, res) => {
const user = await User.findById(req.params.id);
if (!user) return res.status(404).json({ error: 'Not found' });
res.json(user);
};
When You'll Hear This
"Put the business logic in the controller." / "The UserController handles all user-related requests."
Related Terms
Middleware
Middleware is like a security checkpoint at an airport.
Model
A model is the trained AI — the finished product.
MVC (MVC)
MVC is like a restaurant: the Model is the kitchen (data and logic), the View is the plate of food (what the user sees), and the Controller is the waiter (...
Route
A route is like a road sign that tells incoming requests where to go.
View
A view is a saved query that looks and acts like a table.