There will be a bunch of posts littered through-out the blog addressing best practices, and how to create clean, neat, and readable code. This is the first of such posts tackling the directory structure of a relatively simple web application.
Now that our application is big enough to require nested routes we will have to rejigger the directory structure so that we don’t have repeated file names in the main directory.
All we need to do is create a separate diretcory for each level of routes – so for the Yelp Camp app I have created a directory for the campground routes and a directory for the comment routes. This is a simple way to go about it that allows us to keep the proper naming convention for our routes.
If you’re adding the directories after the fact, like I am now, you will need to go through your app.js and adjust your routes (adding the new directory name in front of the file name).
You will also have to adjust the call for including partials so that it goes up a directory first (change . to .. ).
That’s all there is to it! Here is a quick look at the file structure.