Answer the question
In order to leave comments, you need to log in
How to open a separate html file in response.write(``);?
There is a code:
var http = require("http");
var server = http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write("<h1>Привет!</h1><p>Вы запросили `" +
request.url + "`</p>");
response.end();
});
server.listen(8000);
response.write("");
Answer the question
In order to leave comments, you need to log in
Why didn't you succeed with fs? Should work
var fs = require('fs'),
path = require('path'),
filePath = path.join(__dirname, 'start.html');
fs.readFile(filePath, { encoding: 'utf-8' }, function(err,data){
if (!err) {
console.log('received data: ' + data);
response.writeHead(200, {'Content-Type': 'text/html'});
response.write(data);
response.end();
} else {
console.log(err);
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question