House Cleaning 1

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 directory 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).

Screenshot from 2018-04-04 12-28-45

You will also have to adjust the call for including partials so that it goes up a directory first (change . to .. ).

Screenshot from 2018-04-04 12-29-07

That’s all there is to it! Here is a quick look at the file structure.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at

Up ↑

%d bloggers like this: