Express.js & Web APIs Flashcards
Express Basics (Routing, Middleware) REST APIs Request Lifecycle Error Handling Authentication & Authorization (43 cards)
What is Express.js?
Express.js is a fast, unopinionated, minimalist web framework for Node.js used to build web and API applications.
What are routes in Express.js?
Routes in Express.js define how the application responds to a client request for a particular endpoint and HTTP method.
How do you define a GET route in Express.js?
app.get(‘/route’, (req, res) => { res.send(‘response’); });
What is middleware in Express.js?
Middleware is a function that has access to the request, response, and next function in the request-response cycle and can modify them.
What are common types of middleware in Express?
Application-level, Router-level, Built-in, and Error-handling middleware.
What is the purpose of REST APIs?
REST APIs expose resources using standard HTTP methods, enabling stateless communication between client and server.
What is the lifecycle of a request in Express?
Request → Middleware stack → Route handler → Response → Optional error handling middleware.
How does Express handle errors?
By passing an error to next(err)
, Express will skip remaining middleware and move to the error-handling middleware.
What is authentication in Express.js?
Authentication verifies a user’s identity using credentials like username/password or tokens.
What is authorization in Express.js?
Authorization determines what an authenticated user is allowed to do (e.g., access resources or endpoints).
What’s the difference between authentication and authorization?
Authentication verifies who the user is; authorization verifies what the user has access to.
How can you implement JWT-based authentication in Express?
By signing a token during login and verifying it in a middleware using a library like jsonwebtoken
.
What are the advantages of Express.js?
Simple to use, large ecosystem, flexible, supports middleware, and excellent community support.
What are the disadvantages of Express.js?
Less structured, requires manual error handling, lacks built-in advanced features, and can get messy with large codebases.
What is a best practice for structuring Express apps?
Use MVC or modular folder structure, separate routes/controllers/middleware, and apply error handling globally.
What’s a common use case for Express.js?
Building REST APIs, backend for web or mobile apps, or proxy servers.
How does Express.js impact system design?
It promotes modular and scalable design, supports middleware chaining, and allows easy integration with databases and services.
Give an example of middleware usage.
app.use(express.json());
parses incoming JSON requests.
Give an example of using async/await in route handlers.
app.get(‘/data’, async (req, res) => { const result = await db.query(); res.send(result); });
What are the architectural implications of using middleware?
Middleware encourages a pipeline architecture where requests pass through layered processing logic.
How can you make Express apps fault-tolerant?
Use global error handling, process monitoring (e.g., PM2), retries, and validation.
How do you monitor Express applications?
Using tools like morgan, winston, Prometheus, Grafana, or integrating APMs like New Relic or Datadog.
How can you debug an Express.js app?
Use logging (e.g., console.log
, winston
), the Node.js debugger, or VS Code debugging tools.
What are tradeoffs of using Express over a full-fledged framework?
Express offers flexibility but lacks conventions and features, requiring more setup for larger applications.