J
J
JackShcherbakov2019-04-01 00:13:13
Node.js
JackShcherbakov, 2019-04-01 00:13:13

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();
  });

}

Which gives this file:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Текст</title>
</head>
<body>
<h1>Текст</h1>
<img src="logo.png">	
</body>
</html>

But when you visit the page through the browser, there is no picture!
How to make it so that it is?
Thanks in advance to everyone who helps!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question