So I've been trying to figure this out for a while now and the answers that I have found are just confusing, vague without explanation and or, do not work - (At least for me).
First here is my project structure.
.. denotes a folder
- denotes a file
while four | denote a sub directory or file in parent folder
..public
|||| ..html&css
|||| |||| ..main
|||| |||| |||| - main.html
|||| |||| |||| - main.css
|||| ..javascript
|||| |||| -server.js
Hopefully the above project structure is understandable, Stack Overflows formatting is tough to work with.
Here is my code - server.js
let express = require('express');
let app = express();
app.use(express.static('../html&css'));
let server = app.listen(8080, function () {
app.get(function (req, res) {
res.sendFile();
});
});
let port = server.address().port;
console.log(`Express app listening at ${port}`);
I have seen a few ways to send the files when someone connects to the server, and have managed to get html to send but never both html and css. From researching I've seen a few ways to do this but the way in which they are explained is confusing and no answers I found explain in detail how to accomplish my question along with what and why your doing the things they are saying to accomplish it.
I have just been getting a lot about routes, static, app.get this and app.get that, res.sendFile
and some other mumbojumbo but not any of it is really making sense. It also doesn't help that most of the answers don't have the persons complete project structure. If they did understanding which routes were doing what would be much easier.
This link seemed to be the best answer I came across but because of lack of project structure I cannot implement it into my own project and thus understand how it works.
If someone could even just explain how that works with a project structure implemented in their answer I would be grateful, otherwise if they have another way of doing it through the use of the fs
module and express or something else.
I hope my question is understandable clear. Thank you for your time.