Tell us what’s happening:
I’m stuck on Build a Submission Form - Lesson 17. Help me please,
Your code so far
// middleware/error.middleware.js
function notFoundHandler(req, res, next) {
const error = new Error(`Cannot find ${req.originalUrl}`);
error.status = 404;
next(error);
}
// routes/api.routes.js
import { Router } from "express";
const router = Router();
router.get("/", (req, res) => {
res.send("API is available!");
});
router.get("/crash", (req, res, next) => {
const err = new Error("Database connection failed.");
next(err);
});
router.get("/bad-request", (req, res, next) => {
const err = new Error("Client-side data is missing.");
err.status = 400;
next(err);
});
export default router;
// server.js
import express from "express";
import apiRouter from "./routes/api.routes.js";
const app = express();
app.use((req, res, next) => {
console.log(req.method);
console.log(req.url);
next();
});
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use("/api", apiRouter);
app.listen(3000, () => {
console.log(`Server started, on localhost:3000`);
});
Tests 2 and 3 clearly see the function code, so the file is being read. But Test 1 asserts the function is `undefined`, which suggests it’s trying to import the export and failing — even though the export works when I test it manually. Any ideas what I’m missing? Or is this a known issue with the test runner? Thanks!
P.S.: Running on Codespace
