Answer the question
In order to leave comments, you need to log in
Serving files with a tag on nodejs. How right?
Hello!
There is a nodejs code:
var http = require('http');
var fs = require('fs');
new http.Server(function(req, res){
sendFile("index.html", res);
}).listen(3000);
function sendFile(file_src, res){
var file = new fs.ReadStream('index.html');
file.pipe(res);
file.on('error', function(err){
res.statusCode = 500;
res.end("Server Error");
console.log(err);
});
res.on('close', function(){
file.destroy();
});
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Текст</title>
</head>
<body>
<h1>Текст</h1>
<img src="logo.png">
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question