Reputation: 4609
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.
Upvotes: 4
Views: 4018
Reputation: 1
It is because your content type was initially application/js
so it renders as a app.
Convert it into text
or html
and it will render correctly.
Upvotes: -2
Reputation: 4609
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.
Upvotes: 1