Professional backend Setup :
We commence our project by creating a use model for it. Refer to picture one for a visual representation.
In the model, we observe that we handle images as part of our project.
During this phase, we establish our file and folder structure.
Initially, we initialize an empty Node application.
In our model, we also deal with images. It's crucial to note that when storing images, we utilize third-party services such as Microsoft Azure, Amazon AWS, and Cloudinary.
We narrow our focus when uploading photos or other media from users. We ensure that we store this media on our server to mitigate the impact in case of a sub-connection loss. This guarantees the presence of media on our server.
In the third process, we upload the photos to the third-party platform.
Some companies opt for a directed upload approach, while others use third-party packs. This choice depends on the specific practices of each company.
Concept of GitHub keep files .
"GitHub .keep files," it's a convention sometimes used to ensure that an otherwise empty directory is tracked by Git. In some cases, Git may ignore directories that do not contain any files. To work around this, you can include a placeholder file, often named
.keep
(or any other name you prefer), to indicate that the directory should be kept.Additionally, we consider the concept of GitHub ignore files.
".gitignore" file in GitHub, it's a file used to specify intentionally untracked files that Git should ignore. This is useful to avoid committing files or directories that are specific to your local development environment, build output, or other files that shouldn't be part of the version control history.
Create a
.env
file.Inside the project's root directory, create a
public
folder.Within the
public
folder, create atemp
folder.Place the
.gitkeep
file inside thetemp
folder, allowing it to be pushed to GitHub without having extra files we make files in future initially we upload empty folder.Create a
src
folder within the project's root directory.Inside the
src
folder, create three filesapp,js
constants.js
index.js
.Address the issue of the server restarting repeatedly by exploring different options.
Install the
nodemon
dev dependency to handle server reloading upon changes.Use the dev dependency installation process: insert a '-D' between
npm
and the package name, specifying it as a dev dependency.Reload the server automatically when changes are made in the source files.
To achieve this, write a script for
nodemon
to execute.Formulate the command for the script.
"scripts": {
"dev": "nodemon src/index.js"
},
Create additional folders within our source folder.
Utilize the following folders accordingly:
Controllers: Implement the majority of the application's functionality here.
Database: Write the connection logic for the database.
Middlewares: Implement middleware functions here.
Models: Handle data modeling in this folder.
Routes: Manage routes in this folder.
Utils: Store utility functions in this folder.
Install Prettier plugins so that we can work professionally in a team.
Developers use Prettier and its plugins to ensure a consistent and maintainable codebase, improve collaboration, and save time on manual code formatting. It has become a valuable tool in modern development workflows.
.prettierrc
The .prettierrc file is a configuration file used by the Prettier code formatter. It allows you to customize various formatting options to match the coding style preferences of your project. This file typically resides in the root directory of your project.
.prettierignore
The .prettierignore file is used to specify files and directories that should be excluded from Prettier formatting. It works similarly to the commonly used .gitignore file but is specific to Prettier.
{
"singleQuote": false,
"bracketSpacing": true,
"tabWidth": 2,
"trailingComma": "es5",
"semi": true
}
```
Folder Structure:
Thanks to Hitesh Choudhary Sir, I learned all this stuffs from his YouTube channel: