mardi 28 juin 2016

Changing a file directory when using socket.io and node.js?


I have created a successful connection and handled events of someone connecting and disconnecting. However I am now trying to clean up my folders to create something that is a bit more clean to work with.

I have looked at some examples of changing directories, however it seems that I am missing something.

I am quite new to using node and socket, so might seem a bit obvious with the problem.

My basic file structure is i have a main app folder, with an index.html file, server folder with all the relevant node and socket code, then a public folder with css, js, image folders.

File Structure

So my index is in the route. I do also find when I try linking stylesheets and js files it returns a 404 error. Not entirely sure. Any help would be greatly appreciated.

// Sets a base path for acessing all files
app.use(express.static('/'));

app.get("/", function(req, res){
    res.sendFile(__dirname + './index.html');
});

EDIT:

Updated file structure: New Structure


Aucun commentaire:

Enregistrer un commentaire