In node.js express , the default router always jump to index.html static file

My default router is :

app.get('/', function (req, res) {
    console.log("default");
    res.send("ok");
});

If I don't have a index.html in my static directory, the log and send will output as will,

but when I add index.html, the router will direct jump to the page, then I change the name index to another name, it doesn't jump again.

Why this happen? How can I change this setting things?

It's your middleware order and configuration that causes this behavior. You presumably are using the static middleware and by default that happens before the app.router middleware. The solution is either:

  • configure your static middleware to only serve exact file matches without any automatic index.html behavior
  • put app.user(app.router); before your static middleware