node.js - 带有socketIO的expressJs中的最佳文件夹结构
问题描述
什么是项目的最佳文件夹结构,包括:
- 2个数据库(mongodb、influxdb)
- 套接字 io ...
解决方案
这一切都取决于个人喜好。使您的文件夹结构以您最舒适的方式工作。
例如,我喜欢根据代码的用途将我的代码拆分为子模块或简单地说位于不同的目录中。
我个人会使用几个文件夹:
.{src}
├── controllers # All controller operations according the routes are stored here
│ ├── authController.ts # Handles authentication requests
│ ├── usersController.ts # Handles users route requests
│ └── ...
│
├── database # All database connections are stored here. For example you have two databases
│ ├── db.ts # Initialize DB connection
│ └── ...
│
├── middleware
│ ├── authenticated.ts # Decode and verify JWT token
│ ├── error.ts # Common Error Handler
│ ├── logger.ts # Control logging levels
│ └── ...
│
├── models # Simple descriptor of the database tables
│ ├── usersModel.ts # DB model for users
│ └── ...
│
├── schema # Schemas that are used for CRUD operations with the models
│ ├── users.ts # DB Schema for users
│ └── ...
│
├── listeners
│ ├── socketsManager.ts # Socket listeners/emitters handle
│ └── ...
│
├── app.ts # Entry file for the project
├── .env # Store environment variables
├── routes.ts # All routes initializer
└── ...
尽管您可能不喜欢我的命名或顺序,但您可以创建自己喜欢的名称。您可能要做的另一件事是查看互联网上的一些约定或一些最流行的项目,如框架。
毕竟,这完全取决于您的需求以及您使用的舒适度。
推荐阅读
- vue.js - 如何基于 vuex 状态模糊或聚焦 vuejs 组件
- android - Github GraphQl 获取 REPOSITORY 订阅者数量和订阅者列表
- css - 在没有额外 div 的横幅中居中文本
- python - Python值错误(ValueError:没有足够的值来解包(预期2,得到1)
- python - 无法访问要在类中使用的变量
- javascript - 如何用 javascript 完全替换页面或其标题的 CSS 样式?
- c++ - C++ 使用同一个函数时如何修改间距
- java - 使用多维数组 - Java
- android-studio - 如何让颤振在没有任何设备(真实或虚拟)的情况下在 android studio 中运行?
- javascript - 为什么 react-bootstrap 没有向我的网格布局添加样式