I have created a server with Node.JS express where I open html file in public folder.
app.use(express.static(__dirname + '/public'));
app.listen(8080);
I have done this before without any problems. But in this project when I try to open the server in 127.0.0.1:8080 it automatically downloads the index.html file. I tried it with different browsers but result was same.
UPDATE
I could open html file in Edge. But it was very very slow like it is processing some thing. And it got stuck when I send a request to the server.
I tried opening the HTML file separately with the browser it works without any problem.
And tried giving another html file location, result was same.
I do not know what is the exact problem here. But I got to know that it has to do something with content type as td-lambda mentioned in the comments. So I found a solution like this.
var express = require('express');
var app = express();
var server = app.listen(8080);
app.set({
'Content-Type': 'text/html'
});
app.use(express.static(__dirname + '/public'));
And this solved my problem.
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