Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help with express.router not working ?? #36

Open
FireFighter1017 opened this issue Jan 9, 2022 · 1 comment
Open

Need help with express.router not working ?? #36

FireFighter1017 opened this issue Jan 9, 2022 · 1 comment

Comments

@FireFighter1017
Copy link

I'm at the step where you implement the routes using express.router.
If I use "app.get("/"... " in app.js it works fine. But when I try app.use("/", require("./routes/index")) it fails with "GET / 404".
It can't read the route.
Is there is something I'm not doing right?

@FireFighter1017
Copy link
Author

Something was definitely not right in the way I built the app.
I ended up using WSL to create a new app from scratch using express-generator and the router finally works.
The only thing I thought was my mistake is that the "app" express object in app.js is not the same object as the "express" object in routes/index.js and that would explain why it not capable of finding a working route for "/".
Even though my declarations were made exactly the same way and in the same sequence Brad shows in his video, I ended up creating two different objects that aren't sharing the same express instance.

I have seen other people complining about similar issues and that recreating the app would solve it.
I tried several times, both on Windows and on Ubuntu WSL.

The one that worked for me was using express-generator in a Ubuntu WSL session

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant