DEV Community

Keely
Keely

Posted on

MVC file structure notes

Homework: Blog

New File Structure

server.js > adding in many new packages that will need to be started to run all these files simultaneously

Controllers

Replaces routes
index.js (similar, uses router object rather than app)
home-routes.js (Express code, addition is a snippet that connects the router to a view)
api > index.js, user-routes.js (ie. this is using Express to save login variables

Utils

new
helpers.js
In this example, this is adding formatting and pulling in time and date. Separate middleware from routes. If a piece of code is used in multiple routes, can pull that out into it's own file that each route can tap into as needed.

Views

new
Basically these files are creating html code that can pull in data from the database and are strung together using Express.
Pages not nested in other folders here but they are using the file in the layout to complete the page. The partial files are components that are used on multiple pages.

Public

new
"Static" code that the Views files pull from.
CSS
Images
JS > login.js, logout.js

no change
Config
db
Models
Seeds

Documentation:
https://www.npmjs.com/package/express-handlebars << this is the one listed out in the dependencies of the package.json
https://www.npmjs.com/package/express

Top comments (0)