I'm creating a web server using Node & Express. I've set up express.static on my express instance to point to a folder called public that contains index.html, but I've yet to set up any routes.
var express = require("express");
var app = express();
app.use(express.static("public"));
However, when I connect to the server with a browser I receive index.html even though I haven't specifically requested it in the url. Why is this? Does the browser automatically request index.html if no path is set, or is this some sort of default route in Express or Node?
It's not the browser that looks for index.html if no path is set, it's actually what's sent back from the server. Typically by default, servers are configured to give back an index.html or index.php if no page is explicitly requested. Depending on the server, you can have whatever page you want get sent back to the client if no path is specified by editing the configuration file(s).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With