Monday, 4 May 2020

Node/Express/ejs structure of frontend files

I'm learning Javascript/Node and to do so I'm making a dashboard app with Express. As my code grows, my biggest challenge is structure. I've already seperated my routes, business logic and database queries (which makes things very clean and clear), but I'm messing up my frontend stuff.Currently, my view engine is ejs because I need to dynamically insert stuff in my html pages before sending them out. The public folder is served viaapp.use(express.static('./public')); and every .ejs file is served in the corresponding route (which are protected by access level check of logged in users) using:if (req.session.accesslevel > 2) { return res.render('/usermanagement', { data: userList } ); } Underneath is a very simplified version of my current folder structure. I find it very annoying, because when I update the usermanagement page, I'm hopping between a lot of different folders. It doesn't make sense to seperate files by file type...publicjscreateUser.jsdeleteUser.jsupdateUser.jscsshome.cssusermanagement.cssimagesviewshome.ejsusermanagement.ejs... but I'd rather bundle them by function. My ideal structure would be more a React-like structure that bundles relevant files together:viewshomehome.ejshome.cssusermanagementusermanagement.ejsusermanagement.csscreateUser.jsdeleteUser.jsupdateUser.jsPoint is, I have no idea to serve a structure like this. Can someone point me in the right direction?

Submitted May 04, 2020 at 10:38AM by Necessary_Mammoth

No comments:

Post a Comment