Capstone topics from the end of the program: how to set up a full-stack backend project, work with npm and Git, test APIs with Postman or curl, apply layering and REST habits, and prepare for deployment and the mock interview. These patterns tie Express, SQL, and deployment lessons into day-to-day engineering practice.

How to return consistent API errors — Intermediate

Use JSON error objects and appropriate status codes; centralize formatting in error middleware.
Learn: Clients and frontends depend on predictable error JSON. Pick a shape (e.g. { error: string }) and use it for validation, not found, and server errors.

Supplementary examples

errorHandler shape

function errorHandler(err, req, res, next) {
  const status = err.status || 500;
  res.status(status).json({
    error: err.message,
    ...(process.env.NODE_ENV === "development" && { stack: err.stack }),
  });
}

Course example

// Validation
res.status(400).json({ error: "username is required" });

// Not found (in service or controller)
const err = new Error("User not found");
err.status = 404;
throw err;

// errorHandler sends: { error: err.message }

Additional references & examples

← All Coding & architecture practices · Misc / Other