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

186
Views
GET routes not called in express with html

I have a very simple app so I didn't think I needed a full-fledged front-end template like angular, and I didn't really want to use Jade

app.get('*', function(req, res) {
  res.sendFile(__dirname + '/public/index.html');
});

Basically I'm returning an html file, and I'm able to call other html files like

login.html
signup.html

But what confuses me is that my routes are not called. For example I send a GET request to /login but there is no "LOGIN GET" output

//Edit: even with req, res, I can delete this function below and still receive index.html

app.get('/login',function(req,res){ 
  console.log("LOGIN GET")
  res.sendFile( path.join( __dirname, 'public', 'login.html' ));    
});

How is login.html sent to the client if my route isn't called?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Missing req and res parameters to the route handler. For static file you can also follow https://expressjs.com/en/starter/static-files.html

app.get('/login',function(req, res){ 
  console.log("LOGIN GET")
  res.sendFile( path.join( __dirname, 'public', 'login.html' ));    
});
about 4 years ago · Santiago Trujillo Report

0

You should use the Express router.

var router = express.Router();

And then, you can get

router.get("/login",function(req,res){
  console.log("LOGIN GET")
  res.sendFile( path.join( __dirname, 'public', 'login.html' )); 
});
about 4 years ago · Santiago Trujillo Report

0

My guess is that you're declaring the catch-all route first:

app.get('*', function(req, res) {
  res.sendFile(__dirname + '/public/index.html');
});

app.get('/login',function(req,res){ 
  console.log("LOGIN GET")
  res.sendFile( path.join( __dirname, 'public', 'login.html' ));    
});

Because /login matches *, Express will use the first route to handle requests for /login as well. Generally, with Express you need to declare more specific routes first:

app.get('/login',function(req,res){ 
  console.log("LOGIN GET")
  res.sendFile( path.join( __dirname, 'public', 'login.html' ));    
});

app.get('*', function(req, res) {
  res.sendFile(__dirname + '/public/index.html');
});

The reason the other HTML files work is that you probably are using express.static() too (but not showing it).

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!