I have the following basic server:
var express = require('express');
var app = express();
app.get('/', function(req, res){
res.sendfile(__dirname + '/public/index.html');
});
app.listen(8081);
In that index.html I have referenced some CSS that are in the same public folder. The route is correct, since if I open the html with the browser it comes out correctly, but if I enter through the server (that is, in localhost:8081) I get the plain html, without the CSS. What do I have to add in my NodeJS server?
I reference the CSS from the index.html
like this:
<link rel="stylesheet" href="assets/css/main.css" />
Try the following code, basically you would be needing to tell the app where the static files are located (css, js, images, etc.)