Node.js 应用结构,"folder by features" 路由
Node.js app structure, "folder by features" routing
我正在制作一个可扩展的 REST-API,但我几乎找不到关于大型应用程序的高级 node.js 应用程序结构的文章,因为它们中的大多数都使用简单的入门项目。
我正在使用“文件夹功能”结构,基于此article and this answer。
我的问题:以下解决方案的更好结构是什么?
1.将路线保存在单独的文件夹中:
src
product
index.js
product.spec.js
routes
index.js
product.js
user.js
user
index.js
user.spec.js
2。将路由放入对应文件夹:
src
product
index.js
product.route.js
product.spec.js
user
index.js
user.route.js
user.spec.js
使用 index.js
文件中的路由。
有没有更好的解决方案?
任何关于高级、可扩展节点项目结构的文章都将不胜感激!
因为这是一个意见问题,所以这是我的问题:
我的构建将所有内容从 src
迁移到 dist
。有些是编译的,有些只是复制的。然后我直接从 dist
文件夹 运行。
src
api
<api files/folders>
lib
<common lib files/folders>
routes
<Route files (app.use, app.get, etc.)>
static
<static css, images, script, etc.>
<I do not include src code that is compiled in any way>
ui
<LESS, SASS, JS, etc that will be compiled, combined, packed, etc>
views
<ejs files>
app.js
src/ui/**
中的内容被编译并放入 dist/static/**
。
我正在制作一个可扩展的 REST-API,但我几乎找不到关于大型应用程序的高级 node.js 应用程序结构的文章,因为它们中的大多数都使用简单的入门项目。
我正在使用“文件夹功能”结构,基于此article and this answer。
我的问题:以下解决方案的更好结构是什么?
1.将路线保存在单独的文件夹中:
src
product
index.js
product.spec.js
routes
index.js
product.js
user.js
user
index.js
user.spec.js
2。将路由放入对应文件夹:
src
product
index.js
product.route.js
product.spec.js
user
index.js
user.route.js
user.spec.js
使用 index.js
文件中的路由。
有没有更好的解决方案?
任何关于高级、可扩展节点项目结构的文章都将不胜感激!
因为这是一个意见问题,所以这是我的问题:
我的构建将所有内容从 src
迁移到 dist
。有些是编译的,有些只是复制的。然后我直接从 dist
文件夹 运行。
src
api
<api files/folders>
lib
<common lib files/folders>
routes
<Route files (app.use, app.get, etc.)>
static
<static css, images, script, etc.>
<I do not include src code that is compiled in any way>
ui
<LESS, SASS, JS, etc that will be compiled, combined, packed, etc>
views
<ejs files>
app.js
src/ui/**
中的内容被编译并放入 dist/static/**
。