I'm not very familiar with NodeJS and started to work with it and Express. Now I'm getting the following content: I want to serve an index.html file but make some other things before that. But since I'm using app.use(express.static(__dirname + '/client/public'));
a browser request does not affect the app.get("/")
function. How do I solve that problem?
app.use(express.static(__dirname + '/client/src/css'));
app.use(express.static(__dirname + '/client/public'));
app.get('/', function (req, res) {
console.log('###GET REQUEST received');
console.log(req);
res.sendFile(__dirname + '/index.html');
});
Thank you in advance!
Order matters. Put your app.get route prior to the Express.static declaration.
Or, disable the indexing.
express.static(path, {index: false})
index
: sends the specified directory index file; set tofalse
to disable directory indexing.from https://expressjs.com/en/4x/api.html#express.static
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