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

132
Views
Unexpexted 404 in express.js

I really don't understand why node(express) just render index page and return 404 for other pages ("comproAffitto" in the example).

app.js

var index = require('./routes/index');
var comproAffitto= require ('./routes/comproAffitto');

...
...

app.use('/', index);
app.use('/comproAffitto', comproAffitto);

routes/index.js

var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});

module.exports = router;

routes/comproAffitto.js

var express = require('express');
var router = express.Router();

/* GET comproAffitto page. */
router.get('/comproAffitto', function(req, res, next) {
console.log("dentro");
res.render('comproAffitto', { title: 'Exprrress' });
});

module.exports = router;

html href

<a href="/comproAffitto/" class ....

console log

GET /comproAffitto/ 404

where is the problem?

thank you all

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You are constructing the path two times: /comproAffitto/comproAffitto. You should remove one of them or here:

app.use('/', comproAffitto);

or there:

routes/comproAffitto.js

var express = require('express');
var router = express.Router();

/* GET comproAffitto page. */
router.get('/', function(req, res, next) {
console.log("dentro");
res.render('comproAffitto', { title: 'Exprrress' });
});

module.exports = router;

leaving app.use('/comproAffitto', comproAffitto);

about 4 years ago · Santiago Trujillo Report

0

You defined /comproAffitto/comproAffitto instead of /comproAffitto

You would need to either change this:

app.use('/comproAffitto', comproAffitto);

to this:

app.use('/', comproAffitto);

or this:

router.get('/comproAffitto', function(req, res, next) {

to this:

router.get('/', function(req, res, next) {
about 4 years ago · Santiago Trujillo 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!