I
I
Ingerniated2016-10-09 00:20:47
Node.js
Ingerniated, 2016-10-09 00:20:47

Why is fs.readFile not reading?

Why does the site's code display instead of the visual page of the site?
var http = require("http");
var fs = require("fs");
http.createServer(function(request, response) {
fs.readFile("index.html", {encoding: "utf-8"}, function(error, file) {
response.writeHead(200, {"Content-type" : "text/plain"});
response.write(file);
response.end();
});
}).listen(8000);
console.log('Server running on port 8000');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Finom, 2016-10-09
@Ingernirated

{"Content-type" : "text/plain"} -> {"Content-type" : "text/html"}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question