Bug with the router class #6171
-
This is my code // ... // bind it as an express middleware app.listen(3000) which throws this error $ bun run index.js Bun v1.1.30 (Linux x64) |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 1 reply
-
Whats require-triage label? |
Beta Was this translation helpful? Give feedback.
-
@evokerking1 The Triage Process indicates that it means further triaging is needed to properly classify the issue. |
Beta Was this translation helpful? Give feedback.
-
You wrote const router = app.Router() |
Beta Was this translation helpful? Give feedback.
-
That is all my code. |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
Agree! this should work const router = app.Router() |
Beta Was this translation helpful? Give feedback.
-
i tried that stuff but it stills throws an error |
Beta Was this translation helpful? Give feedback.
-
The router's constructor ( const express = require("express"); // the express module
const app = express(); // instantiate the express app; note the `()` at the end
const router = express.Router(); // Router constructor is a part of the module (`express`), not `app`;
// `()` also required
// This demo mounts a router `router` (with a simple GET handler on `/`) on `/r`
router.get("/", (req, res) => res.send("ok"));
app.use("/r", router);
const PORT = 8080;
const server = app.listen(PORT, async () => {
const r = await fetch(`http://127.0.0.1:${PORT}/r/`);
console.log(r.status, await r.text());
server.close();
}); You can also find some examples in the documentation. |
Beta Was this translation helpful? Give feedback.
The router's constructor (
Router()
) is a part of the"express"
module, not the instance of the app.