We will be using a similar modular file and folder structure as seen in the previous chapter. Initially, we will create the following folders and files:
- controllers: This folder will house the files that will contain our application's main business logic.
- middleware: This folder will contain all our custom middleware.
- models: This folder will contain our data objects and mongoose schemas.
- views: This folder will contain the template files for our application.
- index.js: This is the entry point for our application. Here, we will initialize the application, register all the required middleware, and start the server.
- db.js: This is where we will connect to our MongoDB database using Mongoose.
To create the needed folders, you can run the following command in the terminal:
mkdir controllers middleware models views
To create the needed files, you can run this command in the terminal:
touch index.js db.js
After initializing the project, installing the needed dependencies, and creating the required files and folders, we should have the following structure:
├── controllers
├── db.js
├── index.js
├── middleware
├── models
├── package-lock.json
├── package.json
└── views