I am trying to get Node to display an HTML file (using fs, http, and express) but the image in that file displays as a broken link symbol.
I have tried writing the following code, I have multiple modifications, but to no avail.
var http = require('http');
var fs = require('fs');
var express = require('express');
var path = require('path');
var dt = require('./modules/myFirstModule');
var port = 3000;
var app = express();
app.use(express.static(path.join(__dirname + 'public')));
console.log(__dirname);
app.use('/images', express.static(path.join(__dirname + 'public' + 'images')));
http.createServer(function (req, res)
{
//res.writeHead(200, {'Content-Type': 'text/html'});
console.log("Server Created!");
fs.readFile('./html/index.html', function(err, data)
{
res.write(data);
res.end();
});
}).listen(port);
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script src="app.js"></script>
</head>
<body>
<img src="images/2016-collage.jpg"/>
</body>
</html>
I am expecting to see the image displayed on the webpage, but I just get the broken image link symbol.