TGViewer
Coding Interview Preparation Coding Interview Preparation @coding_interview_preparation · 5.9K subscribers
Post #1196 517
✅ Backend Basics Interview Questions – Part 3 (Express.js Middleware) 🚀🧠

📍 1. What is Middleware in Express.js?
A:
Middleware are functions that execute during the request-response cycle. They can modify req/res, execute code, or end the request.

📍 2. Types of Middleware 
- Application-level: Applied to all routes or specific routes 
- Router-level: Applied to router instances 
- Built-in: e.g., express.json(), express.static() 
- Third-party: e.g., cors, morgan, helmet

📍 3. Example – Logging Middleware 
app.use((req, res, next) => {
  console.log(`req.method{req.url}`);
  next(); // Pass to next middleware/route
});

📍 4. Built-in Middleware
app.use(express.json()); // Parses JSON body
app.use(express.urlencoded({ extended: true })); // Parses URL-encoded body

📍 5. Router-level Middleware
const router = express.Router();
router.use((req, res, next) => {
  console.log('Router Middleware Active');
  next();
});

📍 6. Error-handling Middleware 
app.use((err, req, res, next) => {
  console.error(err.stack);
  res.status(500).send('Something broke!');
});

📍 7. Chaining Middleware
app.get('/profile', authMiddleware, logMiddleware, (req, res) => {
  res.send('User Profile');
});

💡 Pro Tip: Middleware order matters — always place error-handling middleware last.

💬 Tap ❤️ for more!
More from @coding_interview_preparation
  1. Oct 10, 2026100 SQL interview questions
  2. Oct 8, 2026If you're prepping for system design interviews, this repo is gold It contains a curated,…
  3. Oct 6, 2026document post
  4. Oct 4, 2026💼 Why Your Resume Gets Rejected Before a Human Reads It You may have good skills and proj…
  5. Oct 2, 2026🧠 Coding Myths You Should Stop Believing There's a lot of advice online about learning to…
  6. Oct 1, 2026Most Asked Topics in AI Engineer Interviews Based on 2026 candidate reports
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →