簡體   English   中英

Node.js app結構,“按功能分類”路由

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

我正在制作一個可擴展的REST-API,但我幾乎沒有找到關於高級應用程序的高級node.js應用程序結構的文章,因為大多數都使用簡單的入門項目。

我正在使用“ 逐個功能 ”結構,基於這篇文章和這個答案

我的問題: 以下解決方案的更好結構是什么?

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文件中的路由。

還有更好的解決方案嗎?

任何有關高級,可擴展節點項目結構的文章都將受到贊賞!

由於這是一個意見問題,這是我的:

我的構建遷移了從srcdist所有東西。 有些是編譯的,有些是剛剛復制的。 然后我直接從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/**

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM