In this video, Emmanuel Henri sets the folder structure for the following videos. Then he adds the proper files inside of the folders.
- [Narrator] So before we start adding end points to our server, let's set up our folder structure for a project. I personally put everything in the source folder, and then start branching out the folders and files I'll use for the server, my controllers, models, and routes. Let's get to it. So the first thing I want you to do is use whatever techniques your editor permits you, either click on the plus here for new folder, or right click in the directory here, and create a new folder. And this new folder we'll call source.
This is where all our files are going to be. Then right click again, create a new folder again, and then create the controllers folder. And this is where we're going to have most of the logic of our server, so when we need to return specific data and send it to our API, then this is where our controllers are going to be. So we're using kind of the MVC model here. The only letter in the MVC we're not using is the V, so we're going to do the models and the controllers.
So the next folder we need to create is the model, or models, plural, and this is where we're going to create our schema, this is where we're going to connect to mongodb and so on and so forth. So let's go ahead and create one last folder inside of our source, and this one we'll call routes. And the routes are going to be where we create our API end points. So let's go ahead and create a file in each of those.
Right click, new file, and then do crmController. And the reason why we have a specific controller for CRM, let's say you take this course, and you create the CRM with us, and then you want to create more type of data inside of your CRM application. You would have a second controller that's properly named whatever is the other function you want to create, or the other type of data you want to offer to your user or end points.
Therefore this is why I'm specific about doing crmController. Then let's go ahead and do a new file inside of our models, and we'll create the crmModel.js. Same thing for routes. crmRoutes. And again, for the same reason as we explained for the controller, we are specifically naming the routes and the model because we may need to create more types of routes inside of our application.
And sometimes the way we would split our folders here to create more types of data would have routes and then a subfolder that's called crm and then inside of crm you would have specific get calls or specific put calls, and then, and so on and so forth. So for the time being we'll do these files the way they're structured right now. So this is fairly straightforward, and we'll start adding items to these files as we add our code to our route, our models, and our controllers.
- Setting up a project and a server
- Setting up a database and schema
- Creating POST, GET, PUT, and DELETE endpoints
- Serving files