Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

295
Views
Cannot GET routes other than "/" express

I'm trying to create a web app with the MVC pattern and express in node.js. This is my project structure: project structure image

app.js:

let express = require("express");
let hbs = require("hbs");
let app = express();

let indexController = require("./controllers/indexController");
let loginController = require("./controllers/loginController");

app.set("view engine", "hbs");

app.use('/login', loginController);
app.use('/', indexController);

app.listen(3000);

loginController.js:

let express = require("express");
let router = express.Router();

router.get('/login', (req, res) => {
    res.render("login");
});

module.exports = router;

The problem is that I can access the index page ("/") but not the login page ("/login") even when the code for both is almost identical.

Here's the code of indexController.js:

let express = require("express");
let router = express.Router();

router.get('/', (req, res) => {
    res.render("index");
});

module.exports = router;

I don't really know what's happening, I'm kinda new to express and MVC and couldn't find anything online, please help :)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have 'login' twice. The first one is enough in app.use('/login', loginController); Inside, you can remove the other

router.get('/', (req, res) => {
    res.render("login");
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!