I have a clientj nodejs server encapsulated in a client folder to make it easier to manage the folder structure for index.html. Then links and scripts should not load without problems.
client folder /index.html /style.css /script.js closer folder /closure /etc. app.js package.json utility.js
In my app.js file I have normal
app.get ('/', function (req,res) { res.render('index.html'); });
and when I start and go to the local host port, the file loads, but when I open the chrome console, I see that the index.html file could not load any of the scripts with 404 error that was not found. I notice that many express apps seem to have a general outline of something like strings
this app.set('views', __dirname + '/client'); this app.use(express.static(__dirname + "./client")); this app.use('client', express.directory('client'));
but I see no explanation for the differences between app.use and app.set, nor a good explanation, the best I could find was
app.set ('views', __dirname + '/ views'): use. / views as the default path for client templates
from Alex Young is an article , but even that was a bit lean and dry for me, I hope to explain a little deeper why the index file cannot load the link at the same directory level as it is.
<link rel="stylesheet" type="text/css" href="style.css" />
I look at this and I cannot find the problem.
source share