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

59
Views
Express.js middleware function isn't getting called

I am using Express.js and I am having trouble routing to a middleware function that I want to get called. I have app.js, userauth.routes.js, and index.js. If the url starts with /user/, it is intended to go to a function in userauth.routes.js to verify the session. Afterwards, it is supposed to be routed to index.js. Unfortunately, it seems like the validation part is completely skipped over.

app.js:

var userauthRouter = require('./routes/userauth.routes.js');
var indexRouter = require('./routes');

app.use('/user/', userauthRouter);
app.use('/', indexRouter);

userauth.routes.js:

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

router.get("/*", function(req, res, next){
    console.log("user authentication");
    next();
});

module.exports = router;

index.js

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

/* GET home page. */
router.get('/*', function(req, res, next) {
  res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});

module.exports = router;

At the moment, I should see user authentication in the output but I see nothing.

about 4 years ago · Juan Pablo Isaza
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!