To Admins, I have spent the whole day searching, trying and retrying many different answers dealing with Node Js, Express and Static files I found all over stackoverflow and on the internet and I still have not found a single piece of code or hints or clues that help me one bit. So, if this question that I am asking is very similar or duplicate to others, I apologize. I am frustrated.
Having said that I searched online for a very very simple EXAMPLE of what I am trying to do. Then, I followed the tutorial to the TEETH and still it won't work as expected. All I want to be able to do is have NodeJs server serve static files like images and javascript. Here is the code.
NodeJS or Server.js
const express = require('express');
const app = express();
const PORT = 3000;
app.use(express.static('public'));
app.get('/', (req, res) => {
res.send('Hello World!'); <--- This does not load index.html.
});
//app.get("/",function(req,res){
// res.sendFile(__dirname + '/index.html'); <---this what I added to load index.html
//});
app.listen(PORT, () => console.log(`Server listening on port: ${PORT}`));
index.html
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hello, World!</h1>
<img src="shark.png" alt="shark">
</body>
</html>
The interesting thing about this simple code is that on the client side (Browser) there is not a single error in the console.
So, what is wrong with this code? Why is this code refuseing to serve simple image file?