So I am trying to learn how to use expressJS and nodeJS and I am runnning into a problem where the CSS file can't be found (404 error) when I start the server and load the html page. The html page loads fine, but it is not styled when I have the server load it. When I load the page without the server, the page is styled. Here is my code for express and node file:
var http = require('http'),
express = require('express');
app = express();
app.get('/', function(req,res){
res.sendFile(__dirname + '/index.html');
});
app.use(express.static('public'));
app.listen(3000);
The html link for the css is:
<link href="public/main.css" rel="stylesheet">
The file structure is
FrontEnd(folder)
- index.html
index.js
public(folder)
- main.css
What am I doing wrong? I have googled and looked at documentation but have not figured out the problem so far.