简体   繁体   English

Node.js app结构,“按功能分类”路由

[英]Node.js app structure, “folder by features” routing

I'm making a scalable REST-API, but I barely find articles on advanced node.js application structures in terms of a big application, since most of them are using simple starter projects. 我正在制作一个可扩展的REST-API,但我几乎没有找到关于高级应用程序的高级node.js应用程序结构的文章,因为大多数都使用简单的入门项目。

I'm using the " folder-by-feature " structure, based on this article and this answer . 我正在使用“ 逐个功能 ”结构,基于这篇文章和这个答案

My question: what is the better structure of the solutions bellow ? 我的问题: 以下解决方案的更好结构是什么?

1. Keep the routes in a separate folder: 1.将路线保存在单独的文件夹中:

src
  product
    index.js
    product.spec.js
  routes
    index.js
    product.js
    user.js
  user
    index.js
    user.spec.js

2. Put the route into its corresponding folder: 2.将路径放入相应的文件夹:

src
  product
    index.js
    product.route.js
    product.spec.js
  user
    index.js
    user.route.js
    user.spec.js

Using the routes in the index.js files. 使用index.js文件中的路由。

Are there any better solutions? 还有更好的解决方案吗?

Any article about advanced, scalable node project structures would be appreciated! 任何有关高级,可扩展节点项目结构的文章都将受到赞赏!

Since this is an opinion question here is mine: 由于这是一个意见问题,这是我的:

My build migrates everything from src to dist . 我的构建迁移了从srcdist所有东西。 Some is compiled and some is just copied. 有些是编译的,有些是刚刚复制的。 I then run directly from the dist folder. 然后我直接从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

Things in src/ui/** get compiled and placed into dist/static/** . src/ui/**被编译并放入dist/static/**

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM